【发布时间】:2018-05-16 07:49:06
【问题描述】:
最近,我开始使用约束布局,但今天遇到了非常奇怪的行为。当我在 fragment_holiday.xml 中使用 RelativeLayout 作为根而不是 ConstraintLayout 时,输出符合预期,但我想知道 ConstraintLayout 有什么问题。我的代码片段如下,item_row
我得到约束布局的输出(并且在滚动时显示不同的行为,正如您在我分享的屏幕截图中看到的那样)---
fragment_holiday.xml
<android.support.constraint.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"
tools:context="com.thepsi.psidashboard.Fragments.HolidayFragment">
<com.thepsi.psidashboard.CustomViews.CustomDatePicker
android:id="@+id/customDatePicker_holiday"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:dateFormat="MONTH_YEAR"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycle_view_holiday"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/general_margin_eight_dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/customDatePicker_holiday" />
</android.support.constraint.ConstraintLayout>
item_holiday.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="wrap_content">
<TextView
android:id="@+id/textView25"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="24 - January - 2017"
android:textColor="@color/colorPrimaryDark"
/>
<TextView
android:id="@+id/textView26"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="Saturday"
android:layout_alignParentEnd="true"
android:textColor="@color/colorPrimaryDark"
/>
<TextView
android:id="@+id/textView27"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:text="Mahavir Jayanti"
android:textAlignment="center"
android:textColor="@android:color/black"
android:layout_below="@+id/textView25"
/>
</RelativeLayout>
预期设计 -
有人可以告诉我我在这里缺少什么吗?
【问题讨论】:
-
检查回收站视图的宽度。给“matchparent”
-
@ArnoldBrown 是的,它有效!!!!!!!但是为什么不建议将 MATCH_PARENT 用于 ConstraintLayout 中包含的小部件的文档中。可以使用 MATCH_CONSTRAINT 定义类似的行为
标签: android android-recyclerview android-constraintlayout