Android layout ScrollView中ConstraintLayout中的屏障的不良行为
我使用的是最新版本的Android layout ScrollView中ConstraintLayout中的屏障的不良行为,android-layout,android-scrollview,android-constraintlayout,Android Layout,Android Scrollview,Android Constraintlayout,我使用的是最新版本的ConstraintLayout,1.1.0-beta4,当其ConstraintLayout位于ScrollView内时,我遇到了屏障问题。布局如下: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.co
ConstraintLayout
,1.1.0-beta4,当其ConstraintLayout
位于ScrollView
内时,我遇到了屏障问题。布局如下:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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.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="wrap_content"
tools:context="rs.agilesolutions.anothertesttodelete.MainActivity"
>
<Button
android:id="@+id/button"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="8dp"
android:text="Button"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="Lorem"
android:textSize="40sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/button"
/>
<TextView
android:id="@+id/txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:text="Ipsum"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button"/>
<android.support.constraint.Barrier
android:id="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="txt1,txt2"
/>
<TextView
android:id="@+id/txtResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="UNDER BARRIER"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/barrier"/>
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#00FF00"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtResult"
/>
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#FF0000"
android:ems="10"
android:hint="password"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText"
/>
</android.support.constraint.ConstraintLayout>
</ScrollView>
,但它看起来是这样的:
首先,在我的real应用程序中,我有很多视图,这就是需要ScrollView
的原因
其次,由于演示的原因,按下按钮,我会更改txt
(带有Lorem文本的视图)的可见性,从而测试下部视图是否正常工作
第三,很明显,因此,ConstraintLayout
没有考虑到在引用屏障的那些视图下,它可以扩展到足以包含其他内容,而是用底部的剩余视图填充已经创建的布局空间
这是ConstraintLayout
实现中的一个错误吗
如果没有这种情况下的代码更改约束,并且不管视图的可见性如何,我都会相应地设置其余视图的位置,我还有其他选择吗?这是1.1.0-beta4版中的一个错误。我将版本降低到beta3,一切正常。对我来说,这看起来是正确的。似乎是beta4中的一个bug。在beta3中,一切看起来都很好。请注意,布局本身上的wrap_内容
可能会有问题。它只能在没有扩展视图的情况下工作(上面的示例代码应该可以工作)。FYI 1.1.0 stable似乎不再有bug了。是的,我知道。这个问题是十个月前提出的,不过还是要谢谢你!我想你已经知道了,但我今天正在处理这个问题,所以把这个放在这里给其他读者看