如何解决如何显示低于底部布局 50% 和高于底部布局 50% 的视图?
我想显示一个 50% 的视图应该覆盖锚视图,而剩下的 50% 应该显示在视图上方。如果底部布局向上移动,则发送媒体图标也向上移动
喜欢 Whatsapp 中的发送按钮。如何实现这一目标?
这是我的 XML 代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/color_black"
tools:context=".activities.MediaPreviewActivity">
<androidx.viewpager.widget.ViewPager
android:id="@+id/media_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_white"/>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_20"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/back_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="@dimen/margin_10"
android:contentDescription="@null"
app:srcCompat="@drawable/ic_back_arrow_white" />
<com.contusfly.views.CircularImageView
android:id="@+id/image_chat_picture"
android:layout_width="@dimen/margin_30"
android:layout_height="@dimen/margin_30"
android:layout_marginStart="@dimen/margin_15"
android:layout_toEndOf="@+id/back_arrow"
android:contentDescription="@null"
app:srcCompat="@drawable/ic_profile" />
<ImageView
android:id="@+id/delete_media"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:contentDescription="@null"
android:padding="@dimen/margin_5"
app:srcCompat="@drawable/ic_delete_media" />
</RelativeLayout>
<ImageView
android:id="@+id/send_media"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:src="@drawable/ic_send_media"
app:layout_constraintBottom_toTopOf="@+id/bottom_layout"
app:layout_constraintEnd_toEndOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="@color/color_black_opacity_55"
android:focusable="true"
android:focusableInTouchMode="true"
app:layout_constraintBottom_toBottomOf="parent">
<ImageView
android:id="@+id/emoji"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_18"
android:layout_marginEnd="@dimen/margin_15"
android:layout_marginBottom="@dimen/margin_18"
android:contentDescription="@null"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/image_caption"
app:layout_constraintEnd_toStartOf="@+id/image_caption"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/ic_emoji" />
<io.github.rockerhieu.emojicon.EmojiconEditText
android:id="@+id/image_caption"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_10"
android:layout_marginBottom="@dimen/margin_10"
android:background="@null"
android:fontFamily="@font/sf_ui_display_regular"
android:hint="@string/title_hint_caption"
android:inputType="textMultiLine|textCapSentences"
android:maxLines="6"
android:paddingTop="@dimen/margin_15"
android:paddingBottom="@dimen/margin_15"
android:textColor="@color/color_white"
android:textColorHint="@color/color_text_hint"
android:textSize="@dimen/text_size_16"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/emoji" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
我想在bottom_layout上方显示send_media图像视图,有没有人知道如何实现这一点?
解决方法
假设您所指的按钮是 send_media
,您必须将其约束更改为:
<ImageView
android:id="@+id/send_media"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:src="@drawable/ic_send_media"
app:layout_constraintTop_toTopOf="@+id/bottom_layout"
app:layout_constraintBottom_toTopOf="@+id/bottom_layout"
app:layout_constraintEnd_toEndOf="parent" />
这样,顶部和底部都被限制在 bottom_layout
的顶部,从而为您提供所需的结果。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。