android - 偏置属性被忽略
问题描述
我有一个简单的水平链视图布局,带有 spread_inside 链样式。当我尝试使用偏差属性将视图移动到所需位置时,我发现偏差属性被忽略了。
这是供参考的布局:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<View
android:id="@+id/view_1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@android:color/black"
app:layout_constraintEnd_toStartOf="@id/view_2"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/view_2"
android:layout_width="90dp"
android:layout_height="90dp"
android:background="@android:color/black"
app:layout_constraintEnd_toStartOf="@id/view_3"
app:layout_constraintStart_toEndOf="@id/view_1"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/view_3"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.2"
app:layout_constraintStart_toEndOf="@id/view_2"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
在这里,我想使用 layout_constraintHorizontal_bias 属性将 view_3 移近 view_2。我怎样才能做到这一点?
解决方案
如果您在视图中使用水平链,则水平偏置不起作用(因为您在同一轴上提供偏置,如果存在水平链,则垂直偏置将起作用,反之亦然);除非你想将它应用到你创建的链的头视图(这是水平链中最左边的视图和垂直链中最顶部的视图);这不是你的情况,在这里。Also, the applied biasing on the head view of the chain only works if the selected chain style is packed. 因此,您应该尝试找到一些其他解决方法来实现您想要的 UI 并忽略使用 chain (here)。
有关更多信息,请参阅:使用 ConstraintLayout 构建响应式 UI
希望我的回答对你有所帮助。
推荐阅读
- python - 学习python,来自有效讲师的正确示例文件。第一次处理它,追加和弹出命令在我的电脑上不起作用
- scala - 如何更正 Scala 构造函数的错误参数?
- python - Matplotlib.savefig 忽略轴并在图像周围绘制黑色边框
- angularjs - 仅从另一页上的选定项目接收数据
- python-3.x - 嵌套 if 语句与多个扁平 if not 语句之间的性能
- javascript - 在vuejs2的js文件中导入js模块
- python - 如何更改 Python 中导入的数据的列值
- optimization - LoadError 使用近似贝叶斯标准
- c++ - c++ 析构函数按值删除指针函数
- javascript - SCRIPT1014:无效字符重音 (`) IE