我正在使用设计支持库中的 PercentRelativeLayout
,我想为 7 英寸和 10 英寸平板电脑设置不同的百分比。
例如,如果我有如下所示的 ImageView
。
<ImageView
android:id="@+id/contactDoc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_widthPercent="70%"
app:layout_heightPercent="70%"
android:layout_centerHorizontal="true"
android:clickable="true"
android:src="@drawable/dashboard_contactdoctor" />
现在,如果我想为 7 英寸平板电脑设置 70%,为 10 英寸平板电脑设置 60%,而不创建不同的布局文件夹,如 sw720dp。我可以做吗? 感谢您的帮助。
最佳答案
这些百分比是 fraction
资源。您应该能够设置 res/values/fractions.xml
和 res/values-sw720dp/fractions.xml
,其中 define the values for the fractions .然后,在布局中使用 @fraction/whatever_you_called_it
。
关于android - 如何在 PercentRelativeLayout 中使百分比动态化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40261570/