android - ConstraintLayout 将宽度设置为全宽
问题描述
我有主要约束布局,还有额外的布局页脚,我将其膨胀并将其添加到我的主要约束中。问题是,即使我设置约束以将宽度设置为完整(match_parent),它也不能将视图居中,但它会包装内容,但它没有扩展到整个屏幕。这是我的代码:
页脚:
<?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"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/background">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
主布局基本上是空约束布局,比我设置的代码如下:
View footerRow = layoutInflater.inflate(R.layout.footer, null, false);
footerRow.setId(R.id.constraint_footer);
mainView.addView(footerRow);
ConstraintSet set = new ConstraintSet();
set.clone(mainView);
set.connect(footerRow.getId(), ConstraintSet.LEFT, ConstraintSet.PARENT_ID, ConstraintSet.LEFT, 0);
set.connect(footerRow.getId(), ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT, 0);
set.connect(footerRow.getId(), ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, 0);
set.applyTo(mainView);
解决方案
基本上这个问题解决了我的问题:Nested Constraint Layout not show if using Match_Constraints
我没有将它附加到父布局。
推荐阅读
- google-pay - 使用 Google Pay 获取 Android 手机中的付款历史记录
- r - R - 使用 Map() 进行类型转换
- pandas - 在 pandas 中跨行添加计数唯一组合
- scheduled-tasks - 无法在谷歌云控制台或 pod 中安排 kubectl exec
- python - Matplotlib 添加数据导致文本下移
- python - 如何在方法中创建全局对象?
- matplotlib - 如何在单个图形上绘制声波、mfcc 和 mel 频谱图?
- python-3.x - Pyspark AES 256 解密(Mode_CFB)长度错误,但它适用于普通 python 3
- sql - Oracle SQL 累积产品
- javascript - 如何增加水平条形图js中每个数据集的顶部和底部填充