我有两个TextView
水平链接并显示在DialogFragment
中。动态设置的两个TextView
可见性,有时tvA
将是可见的,有时tvB
或两者都会显示。
这是我的xml
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_background_color"
android:minWidth="250dp">
<TextView
android:id="@+id/tvElement"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@drawable/shape_back"
android:gravity="center"
android:padding="10dp"
android:text="@string/elements"
android:textColor="@color/item_view_color"
app:layout_constraintEnd_toStartOf="@+id/tvSensor"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvSensor"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@drawable/shape_back"
android:gravity="center"
android:padding="10dp"
android:text="@string/sensors"
android:textColor="@color/item_view_color"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/tvElement"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/rv_channel"
app:layout_constraintGuide_begin="62dp"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_channel"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toTopOf="@+id/btn_ok"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_min="250dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/guideline" />
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_ok"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:background="@drawable/global_button_selector_3"
android:text="@string/ok"
android:textColor="@drawable/global_button_txt_selector_3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rv_channel" />
</android.support.constraint.ConstraintLayout>
结果将是
布局检查器显示
我有两个问题
当此代码在真实设备上运行时,相应的
TexView
的宽度变为零,并且不再可见。但是,当我删除链时,它正在工作。- 醇>
它基于
RecyclerView
,如果它的高度为match_contraints
,它将缩小到一个单元格高度,而不管有多少项目,但是当我给出时match_parent
,它包含在其中显示的项目中。
我不明白我做了什么错误。
感谢您宝贵的时间
答案 0 :(得分:0)
对于第一个问题,宽度不会变为零,但是您的TextView
消失(从屏幕顶部移开),因为它们没有在底部链接,请尝试添加{{1每个TextView
答案 1 :(得分:0)
试试这个。
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_background_color"
android:minWidth="250dp">
<TextView
android:id="@+id/tvElement"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@drawable/shape_back"
android:gravity="center"
android:padding="10dp"
android:text="@string/elements"
android:textColor="@color/item_view_color"
app:layout_constraintEnd_toStartOf="@+id/tvSensor"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvSensor"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@drawable/shape_back"
android:gravity="center"
android:padding="10dp"
android:text="@string/sensors"
android:textColor="@color/item_view_color"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/tvElement"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/rv_channel"
app:layout_constraintGuide_begin="62dp"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_channel"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toTopOf="@+id/btn_ok"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_min="250dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/guideline" />
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_ok"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:background="@drawable/global_button_selector_3"
android:text="@string/ok"
android:textColor="@drawable/global_button_txt_selector_3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rv_channel" />
</android.support.constraint.ConstraintLayout>