android - 如何在 PercentRelativeLayout 中使百分比动态化?

标签 android android-layout android-percentrelativelayout

我正在使用设计支持库中的 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.xmlres/values-sw720dp/fractions.xml,其中 define the values for the fractions .然后,在布局中使用 @fraction/whatever_you_called_it

关于android - 如何在 PercentRelativeLayout 中使百分比动态化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40261570/

相关文章:

Android - 以编程方式更改 EditTextPreference 对话框的肯定按钮文本

android - 生成gradle中的错误错误:否这样的属性:类GradleVersion:JetGradlePlugin

java - 无法转换为 android.widget.AdapterView$OnItemSelectedListener

android - 在android中匹配具有不同分辨率的UI

android - 如何在 Android 上一次获取所有按钮 ID

android - 如何在 CollapsingToolbarLayout 中使用 PercentRelativeLayout?

android - 垂直 Seekbar 填充父项将不起作用

android - Android 单声道 : where is GCMBaseIntentService?

Android PercentRelativeLayout 应该指定宽高

android - 将 LinearLayout 和 "percentage"边距居中