android-constraintlayout 相关问题

Android支持存储库中提供的一种新类型布局,构建于灵活约束系统之上,标记视图相对于彼此的位置。

ConstraintLayout视图已保留空间

我在回收者视图的约束布局下面。我正在隐藏并根据我的recyclerview Adapter中的Database值显示此代码。它的工作原理是问题,但是视图消失后问题仍然存在...

回答 3 投票 0

除非添加绝对尺寸,否则不显示约束布局的问题

我有此布局,并尝试根据位置打开相应的LL。但是,如果我在绝对视图内给出文本视图,则只会显示并绘制第一个线性布局。

回答 1 投票 0

将布局文件包含在约束布局中,而不会影响性能或Android Studio预览

我有一个巨大的布局文件,其中包含一个平面约束布局。我有相同的android.support.constraint.Group元素。我想将它们移到一个单独的文件中,然后包括它们...

回答 1 投票 0

如何在Android约束下禁用点击

我有一个活动布局,该布局具有reyclerview列表,单击过滤器按钮时会在其上方打开另一个布局,但是问题是,当单击过滤器布局上的空白时,它会单击...

回答 1 投票 0

Android约束布局按钮浮动到顶部

[Android上的约束布局存在一些奇怪的问题:如上图所示,下一个按钮位于屏幕的右下角(受约束在右侧和...

回答 1 投票 1

如何在约束布局中删除视图之间的多余空间?

我已经使用android studio中的约束布局为对话框创建了xml布局。按钮下方有一些额外的空间。没有为视图设置填充,底部页边距也为0dp。有白色...

回答 1 投票 0

[设置提示时,EditText不会展开

所以我在ConstraintLayout中有一个simpleEditText。我想要的是让用户开始键入内容,并让EditText扩展以适合他们的输入,这可以按预期工作,直到我添加提示为止。然后...

回答 2 投票 3

约束布局高度占用可用空间

我有一个约束布局,并且在线性布局内部,看起来像是约束在底部的条形图。此外,我还有一个项目(称为SwipeFlingAdapterView),我想将其......>

回答 2 投票 1

错误膨胀了Android 5.0和Android 6.0上的类androidx.constraintlayout.widget.ConstraintLayout。

在Pixel XL API 21上运行我的应用程序,出现以下错误。 E / AndroidRuntime:致命例外:主进程:com.samprojects.sickvibes,PID:4322 java.lang.RuntimeException:无法启动活动...

回答 1 投票 0

如何使用Java设置AdUnitId?

Java代码:mAdView =(AdView)findViewById(R.id.adView); mAdView.setAdSize(AdSize.BANNER); mAdView.setAdUnitId(“ ca-app-pub-3940256099942544 / 6300978111”); AdRequest ...

回答 1 投票 0

MotionLayout中的ViewStub保持不可见

我有一个带有某些视图和ViewStub的现有ConstraintLayout。我将其转换为MotionLayout,但不会显示ViewStub。我有以下布局:

回答 1 投票 1

如何将视图限制为另一个布局文件中的视图?

我的应用程序使用在main_activity布局中定义的tabLayout。然后,每个选项卡都有一个单独的布局文件,用于放置该选项卡的所有视图。在标签布局文件中,我想约束一个...

回答 1 投票 0


如何将浮动按钮固定在屏幕右下角而不固定在布局上

我有一个可滚动的布局,并添加了一个浮动菜单按钮。所有这些都可以,但是按钮固定在布局上的某个位置,我希望将按钮固定在屏幕的底部。如果...

回答 2 投票 0

视图被打包在ConstraintLayout中,视图在LinearLayout中用尽屏幕

我正在像下面那样实现一个注册/登录屏幕,我已经像下面这样使用ConstraintLayout来尝试了这个 [ 我建议您使用所有的屏幕密度,而不要使用所有的密度,您可以使用著名的库SDP或遵循android提供的指南。第二次使用Constraintlayout的Guideline类。这是示例代码片段,您也可以使用此代码片段。 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.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:layout_margin="16dp"> <ImageView android:id="@+id/img" android:layout_width="@dimen/_200sdp" android:layout_height="@dimen/_200sdp" android:layout_marginTop="16dp" android:src="@drawable/ic_launcher" app:layout_constraintBottom_toTopOf="@+id/btn1" app:layout_constraintEnd_toStartOf="@+id/right" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="@+id/left" app:layout_constraintTop_toTopOf="parent" /> <Button android:id="@+id/btn1" android:layout_width="0dp" android:layout_height="wrap_content" android:text="Button 1" app:layout_constraintBottom_toTopOf="@+id/btn2" app:layout_constraintEnd_toStartOf="@+id/right" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="@+id/left" app:layout_constraintTop_toBottomOf="@+id/img" /> <Button android:id="@+id/btn2" android:layout_width="0dp" android:layout_height="wrap_content" android:text="Button 2" app:layout_constraintBottom_toTopOf="@+id/txt_already_member" app:layout_constraintEnd_toStartOf="@+id/right" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="@+id/left" app:layout_constraintTop_toBottomOf="@+id/btn1" /> <TextView android:id="@+id/txt_already_member" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="Already Member? Sign In" android:textSize="16sp" app:layout_constraintBottom_toTopOf="@+id/divider" app:layout_constraintEnd_toStartOf="@+id/right" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="@+id/left" app:layout_constraintTop_toBottomOf="@+id/btn2" /> <TextView android:id="@+id/txt_agreement" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="24dp" android:text="By continuing you agree to our terms and privacy policy" android:textSize="12sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/right" app:layout_constraintStart_toStartOf="@+id/left" app:layout_constraintTop_toTopOf="@+id/divider" app:layout_constraintVertical_bias="1.0" /> <androidx.constraintlayout.widget.Guideline android:id="@+id/left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" app:layout_constraintGuide_begin="@dimen/_16sdp" /> <androidx.constraintlayout.widget.Guideline android:id="@+id/right" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" app:layout_constraintGuide_end="@dimen/_16sdp" /> <androidx.constraintlayout.widget.Guideline android:id="@+id/divider" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintGuide_percent="0.7" app:layout_constraintTop_toBottomOf="@+id/txt_already_member" /> 实际上,我的问题的解决方案是将Guideline中的ConstraintLayout与Guideline的app:layout_constraintGuide_percent属性一起使用,并将视图限制为准则。 由于app:layout_constraintGuide_percent的值是 percentage 而不是dp值,所以不管屏幕的宽度/高度如何,它都响应良好。 示例: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.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" android:layout_margin="16dp" tools:context=".MainActivity"> <ImageView android:id="@+id/img" android:layout_width="250dp" android:layout_height="200dp" android:src="@drawable/ic_launcher_background" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@+id/guideline4" /> <Button android:id="@+id/btn1" android:layout_width="match_parent" android:layout_height="56dp" android:layout_marginStart="20dp" android:layout_marginEnd="20dp" android:text="Button 1" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="1.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@+id/guideline5" /> <Button android:id="@+id/btn2" android:layout_width="match_parent" android:layout_height="56dp" android:layout_marginTop="8dp" android:layout_marginStart="20dp" android:layout_marginEnd="20dp" android:text="Button 2" app:layout_constraintEnd_toEndOf="@+id/btn1" app:layout_constraintStart_toStartOf="@+id/btn1" app:layout_constraintTop_toBottomOf="@+id/btn1" /> <TextView android:id="@+id/txt_already_member" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:layout_marginBottom="16dp" android:text="Already Member? Sign In" android:textSize="16sp" app:layout_constraintBottom_toTopOf="@+id/txt_agreement" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/btn2" /> <TextView android:id="@+id/txt_agreement" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="32dp" android:text="By continuing you agree to our terms and privacy policy " android:textSize="12sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> <androidx.constraintlayout.widget.Guideline android:id="@+id/guideline4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintGuide_percent=".1" /> <androidx.constraintlayout.widget.Guideline android:id="@+id/guideline5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintGuide_percent=".6" /> </androidx.constraintlayout.widget.ConstraintLayout> 非常感谢Rehan Sarwar记得我关于Guideline的内容。

回答 2 投票 0


Android动态视图定位

如果view1不能填满整个宽度,则我需要view2在view1旁边。如果view1的内容为全角(内容填充屏幕的整个宽度),则view2应该在其下方。例如,如果...

回答 2 投票 0

如何在ConstraintLayout中使按钮响应?

我是Android的初学者,想在底部建 立4个按钮,如图所示。中间的一个按钮是不可能的,因为我尝试将其设置为响应式并且消失了。你可以...

回答 3 投票 0

无法更改在约束布局组内引用的视图的可见性

无法更改使用实现'androidx.constraintlayout:constraintlayout:2.0.0-beta4'的约束布局组内正在引用的单个视图的可见性...] >>

回答 1 投票 0

ConstraintLayout仅包装部分内容

我有一个ConstraintLayout,它只包装部分内容,我不明白为什么。下面是我的情况的图形表示形式:我希望mainConstraintLayout包装所有内容。如果...

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.