如何解决为什么 layout_constraintStart_toEndOf 会与 ConstraintLayout 中的第一个控件重叠?
我正在设计一个视图,其中顶部的图片占屏幕的 33%,其余细节占 66%。但是,详细信息部分会像这样重叠图片:
这是我的代码:
<androidx.constraintlayout.widget.ConstraintLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/llImg"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent=".33"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintWidth_percent="1">
<ImageView
android:id="@+id/imgBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<TextView
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:textStyle="italic"
android:textSize="12dp"
android:layout_alignParentBottom="true"
android:textColor="#4c8c4a"
android:id="@+id/lblImgDescription" />
</FrameLayout>
<LinearLayout
android:id="@+id/llTab"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent=".66"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/llImg">
<com.google.android.material.tabs.TabLayout
android:id="@+id/mTabOptions"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
我做了我认为应该是在第一个 llImg
和底部 FrameLayout
添加一个 ID (LinearLayout
) 的逻辑操作我指出了它应该从哪里开始底部:app:layout_constraintStart_toEndOf="@+id/llImg"
。知道我做错了什么吗?
解决方法
app:layout_constraintTop_toBottomOf="@+id/llImg"
这就是你总体上缺少的。我做了一些更改尝试下面的布局。此外,您还缺少 1% 的屏幕,该部分将用作 llTab
的顶部/底部边距,因此请记住这一点。
<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"
>
<FrameLayout
android:id="@+id/llImg"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent=".33"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/imgBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/lblImgDescription"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:gravity="center_horizontal"
android:textColor="#4c8c4a"
android:textSize="12dp"
android:textStyle="italic" />
</FrameLayout>
<LinearLayout
android:id="@+id/llTab"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent=".66"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/llImg">
<com.google.android.material.tabs.TabLayout
android:id="@+id/mTabOptions"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
,
你应该改变
app:layout_constraintStart_toEndOf="@+id/llImg"
到
app:layout_constraintTop_toBottomOf="@+id/llImg"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。