从Android Java中的gradle样式获取layout_width

问题描述 投票:0回答:1

我试图在layout.xml中获得layout_width

productFlavors {
   Free {
        resValue "string", "flavored_layout_width", "10dp"
   }
}

从gradle构建变体。

  <ImageView
        android:id="@+id/image"
        android:layout_width="@string/flavored_layout_width"
        android:layout_height="@string/flavored_layout_height" />

但是它抛出Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: You must supply a layout_width attribute. Caused by: java.lang.UnsupportedOperationException: Binary XML file line #0: You must supply a layout_width attribute.

android android-studio gradle build.gradle android-productflavors
1个回答
0
投票

仅根据风味创建资源文件夹并将此值包含在dimens文件中会更容易吗?

© www.soinside.com 2019 - 2024. All rights reserved.