我目前正在使用 android.support.percent API
我的示例代码
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:text="Completed"
app:layout_widthPercent="40%"
app:layout_heightPercent="40%"
app:layout_marginTopPercent="15%"
app:layout_marginLeftPercent="15%"/>
</android.support.percent.PercentRelativeLayout/>
我的问题:
Percent relative layout fit correctly in Tablets...但是有些 View 在手机上显示得非常小。
所以我只想增加手机的百分比......而不是平板电脑。
我的问题:
如何使用百分比相对布局为手机和平板电脑设置不同的百分比。(如不同的尺寸)
app:layout_heightPercent="40%"//适合平板 但我想增加到 50% 的电话..
最佳答案
你可以使用最小的宽度尺寸
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:text="Completed"
app:layout_widthPercent="@fraction/width"
app:layout_heightPercent="@fraction/height"
app:layout_marginTopPercent="@fraction/margin_top"
app:layout_marginLeftPercent="@fraction/margin_left"/>
</android.support.percent.PercentRelativeLayout/>
在维度上:
维度.xml
<fraction name="width">40%</fraction>
<fraction name="height">40%</fraction>
<fraction name="margin_top">15%</fraction>
<fraction name="margin_left">15%</fraction>
和 dimens.xml (sw 600dp)
<fraction name="width">40%</fraction>
<fraction name="height">50%</fraction>
<fraction name="margin_top">15%</fraction>
<fraction name="margin_left">15%</fraction>
您可以看到设计屏幕的更多详细信息here
关于android - 如何为手机和平板电脑设置不同的百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39847403/