Java 视图的行为是使用ConstraintLayout固定大小,而不是基于屏幕的动态大小
我正在尝试创建一个设置屏幕,下面是Android Studio中的代码和预览 它有几个问题。具有scrollView布局的CardView无法正常工作 <我想,我的<代码> CabVIEW < /C> >在Java 视图的行为是使用ConstraintLayout固定大小,而不是基于屏幕的动态大小,java,android,android-studio,android-constraintlayout,Java,Android,Android Studio,Android Constraintlayout,我正在尝试创建一个设置屏幕,下面是Android Studio中的代码和预览 它有几个问题。具有scrollView布局的CardView无法正常工作 >在 UrSerDeLysFrase和 LogOutBTn的中间进行调整,代码间隔 > DIMEN/YO20SDP 。但是可以看到,它一直延伸到logoutBtn 如果我使用小屏幕手机,CardView也会开始重叠userDetailsLayout 这就像,它制作的是cardwiew固定大小,而不是基于空间的可变大小。我该怎么办 and
userDetailsLayout
这就像,它制作的是cardwiew
固定大小,而不是基于空间的可变大小。我该怎么办
android:layout_margin="@dimen/_20sdp"
app:layout_constraintTop_toBottomOf="@+id/userDetailsLayout"
app:layout_constraintBottom_toTopOf="@+id/logoutBtn"
app:layout_constraintRight_toRightOf="parent"
问题在于
登录BTN
与您的CardView
位于同一父系统中。他们都有
android:layout_margin="@dimen/_20sdp"
这就是它们具有相同宽度的原因,它们都与父对象左右对齐,并且具有相同的边距。因此,如果您希望从CardView
将其设置为20dp,您可以将logoutBtn
嵌套在CardView中,或者只需将logoutBtn
设置为40dp
<TextView
android:id="@+id/logoutBtn"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginBottom="20dp"
android:background="@color/error_red"
android:gravity="center"
android:text="string/logout"
android:textColor="@android:color/white"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
不是100%确定您的意思,但根据代码,我建议您更改:
android:layout_width="0dp"
android:layout_height="0dp"
在视图上指定高度和宽度约束时。否则,约束将不起作用。顺便说一句,不要在constraintlayout中使用太多嵌套布局。每个布局都需要一个全新的测量和渲染过程,这会大大降低应用程序的速度。请参阅指南
和约束光谱比
android:layout_width="0dp"
android:layout_height="0dp"