相关疑难解决方法(0)

Android - 使用维度的ConstraintLayout百分比

有一个问题如何让ConstraintLayout使用百分比值?它的答案显示了如何使用百分比:

<android.support.constraint.Guideline
    android:id="@+id/guideline"
    android:layout_width="1dp"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:layout_constraintGuide_percent="0.5"/>
Run Code Online (Sandbox Code Playgroud)

但是,如果你不想硬编码百分比但使用维度资源它不起作用.

<!-- inside the layout -->

<android.support.constraint.Guideline
    android:id="@+id/guideline"
    android:layout_width="1dp"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:layout_constraintGuide_percent="@dimen/guideline_perc"/>

<!-- inside dimens.xml -->

<dimen name="guideline_perc>0.5</dimen>
Run Code Online (Sandbox Code Playgroud)

您收到以下错误:

Float types not allowed (at 'guideline_perc' with value 0.5).

如果将值替换为1,则返回类似的错误:

Integer types not allowed (at 'guideline_perc' with value 1).

如何在不将值硬编码到布局中的情况下设置百分比?

android percentage dimension android-resources android-constraintlayout

8
推荐指数
2
解决办法
3578
查看次数