android - 如何为手机和平板电脑设置不同的百分比

标签 android android-layout android-percent-layout

我目前正在使用 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% 的电话..

最佳答案

你可以使用最小的宽度尺寸

enter image description here

<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/

相关文章:

Android:如何使用代码改变textview的layout_marginTop?

android - 如何找到每个版本的android支持库源代码

android - android中的屏幕截图

android - 多种小部件尺寸

android - PercentFrameLayout 作为 Recycler View 中的一个项目不起作用

android - 如何访问由 android 默认音乐应用程序创建的播放列表并调用音乐应用程序播放它?

android - onLocationChanged 在应用程序启动时被多次调用

android - 将一个 View 的垂直中心与另一个 View 的顶部对齐

android - 百分比框架布局 : You must supply a layout_width attribute