从维度传递layout_weight引用(维度)

and*_*idu 28 android android-layout android-linearlayout

我需要为不同的屏幕尺寸设备设置不同的布局权重,我想传递维度文件中的值,问题是来自维度文件的引用不断抛出错误

error: Error: Integer types not allowed (at 'progress_widget_item3_weight' with value '9').
Run Code Online (Sandbox Code Playgroud)

要么

error: Error: Float types not allowed (at 'progress_widget_item3_weight' with value '9.1').
Run Code Online (Sandbox Code Playgroud)
<dimen name="progress_widget_item3_weight">9</dimen>
Run Code Online (Sandbox Code Playgroud)

如何传递layout_weight的dimens文件中的值?谢谢

AZ1*_*Z13 51

您可以使用整数来声明和引用整数,而不是维度.

integers.xml中的示例声明:

<resources>
    <integer name="left">1</integer>
    <integer name="right">2</integer>
</resources>
Run Code Online (Sandbox Code Playgroud)

布局中的示例参考:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="@integer/left" />

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="@integer/right" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)