在以前的xml布局中,我有多个视图组,其中包含很少的元素.隐藏每个视图组也会隐藏其所有子元素.因为我想要平面结构并尝试过ConstraintLayout.酷我知道如何链接元素与蔓延正确对齐.由于扁平结构没有包裹LinearLayout,现在我有3个视图隐藏.我想知道是否有替代方案来实现这一目标.
没有约束布局
<RelativeLayout....
..........
..........
<LinearLayout
android:visibility="gone"
tools:visibility="visible"
android:id="@+id/filter_area"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/lblTerminal"
android:background="@color/lightGray"
style="@style/PurpleSubtitle"
android:drawableRight="@drawable/i_down_yellow"
android:drawableEnd="@drawable/i_down_yellow"
android:padding="10dp"
android:text="@string/lblTerminal"
android:layout_weight="5"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<View
android:background="@android:color/black"
android:layout_width="1dp"
android:layout_height="match_parent"/>
<android.support.v7.widget.AppCompatTextView
android:id="@+id/lblCategory"
android:background="@color/lightGray"
android:padding="10dp"
android:drawableRight="@drawable/i_down_yellow"
android:drawableEnd="@drawable/i_down_yellow"
style="@style/PurpleSubtitle"
android:text="@string/lblCategory"
android:layout_weight="5"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
.......
.......
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
约束布局
<android.support.constraint.ConstraintLayout
.....
.....
.....
#happy that i no longer need LinearLayout for align properly
<android.support.v7.widget.AppCompatTextView
android:id="@+id/lblTerminal"
android:background="@color/lightGray"
style="@style/PurpleSubtitle"
android:drawableRight="@drawable/i_down_yellow"
android:drawableEnd="@drawable/i_down_yellow"
android:padding="10dp"
android:text="@string/lblTerminal"
android:layout_weight="5"
android:layout_width="0dp"
android:layout_height="50dp"
app:layout_constraintTop_toBottomOf="@+id/txt_search"
app:layout_constraintRight_toLeftOf="@+id/view3"
app:layout_constraintLeft_toLeftOf="@+id/guideline2"
app:layout_constraintHorizontal_chainStyle="spread"/>
<View
android:background="@android:color/black"
android:layout_width="1dp" …Run Code Online (Sandbox Code Playgroud) xml android visibility android-layout android-constraintlayout
我在ConstraintLayout中添加了3个按钮.我添加了一个按钮来禁用或启用这些按钮.
如果我使用普通的LinearLayout.我可以将所有按钮放在线性布局中,并启用或禁用该特定布局.
但我正在使用ConstraintLayout.所以我需要禁用或启用所有这些按钮,我相信ConstraintLayout必须有一种方法来组合不同的视图.
请指导我如何在ConstriantLayout中对视图进行分组
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp"
android:layout_marginStart="8dp"
app:layout_constraintLeft_toRightOf="@+id/button"
android:layout_marginLeft="8dp"
app:layout_constraintTop_toTopOf="@+id/button" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button3"
app:layout_constraintTop_toTopOf="@+id/button2"
android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="16dp"
android:layout_marginStart="8dp"
app:layout_constraintLeft_toRightOf="@+id/button2"
android:layout_marginLeft="8dp" />
Run Code Online (Sandbox Code Playgroud) performance android android-layout android-linearlayout android-constraintlayout
Has anyone experienced issues with ConstraintLayout group visibility?
I'm using ConstraintLayout 1.1.3 and I'm setting the visibility of group in both XML layout and java code. But it does not change the visibility status. It is always visible.
This is the layout file
<?xml version="1.0" encoding="utf-8"?>
<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">
<ImageView
android:id="@+id/iv_message_icon_activity_dictionary"
android:layout_width="@dimen/message_icon_width"
android:layout_height="@dimen/message_icon_height"
android:layout_marginBottom="@dimen/message_text_view_margin_top"
android:contentDescription="@string/app_name"
android:src="@drawable/icon_error"
app:layout_constraintBottom_toTopOf="@+id/tv_message_activity_dictionary"
app:layout_constraintEnd_toEndOf="@id/tv_message_activity_dictionary"
app:layout_constraintStart_toStartOf="@id/tv_message_activity_dictionary" />
<TextView
android:id="@+id/tv_message_activity_dictionary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:gravity="center"
android:textColor="@color/black"
android:textSize="@dimen/medium_text_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/msg_no_internet" /> …Run Code Online (Sandbox Code Playgroud) android android-layout android-constraintlayout android-app-bundle