Android:ConstraintLayout 在 SDK 4.1.x 上有不同的行为

标签 android android-constraintlayout

我有这个简单的布局:

<android.support.constraint.ConstraintLayout
            android:id="@+id/main_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toTopOf="parent"
            android:paddingLeft="@dimen/keyline_1">

            <com.xxx.ui.widget.CustomTextViewFont
                android:id="@+id/title"
                style="@style/FlatCardTitle"
                android:paddingTop="@dimen/keyline_1"
                android:layout_marginRight="@dimen/keyline_1"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="@+id/actions_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:maxLines="2"
                android:ellipsize="end"
                app:customFont="OpenSans-CondBold.ttf" />

            <FrameLayout
                android:id="@+id/actions_layout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintRight_toRightOf="parent"
                android:visibility="gone">

                .....
            </FrameLayout>

       .....
 </android.support.constraint.ConstraintLayout>

在 Android 5.x 上,actions_layout 正确位于 View 的右侧。但在 4.1.x 中,actions_layout 仍然位于左侧。

感谢大家的支持!

最佳答案

我也遇到了同样的问题。指定顶部和底部约束对我很有帮助。 试试这个方法。

    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintHorizontal_bias="1"

关于Android:ConstraintLayout 在 SDK 4.1.x 上有不同的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43975209/

相关文章:

android - 约束布局基线到基线与自动调整大小

android - ConstraintLayout - 在根部居中 TextView 但不覆盖 Button

android - 如何将约束布局最小宽度设置为xml中另一个 View 的宽度

android - 使用 OpenGL ES 1.0 在 Android 上绘制线条

java - 在 Android Studio 中动态设置按钮的约束

java - 静态方法中的 TimerTask 在执行之前会被垃圾回收吗?

Android VPN 服务路由排除

Android 约束布局 - 将 View 固定到页面底部和另一个 View 下方(而不是介于两者之间)

android - 在 Android 中使用 Volley for GIthub 进行基本身份验证。获取错误代码 422

android - 如何使用 Android Room 运行多个 AND 查询?