Android在Layout中支持百分比

jopen 9年前發布 | 58K 次閱讀 Android Android開發 移動開發

Android Layout終于支持百分比了

Android在Layout中支持百分比

依賴

xml dependencies { compile 'com.android.support:percent:22.2.0' }

示例

```xml
<android.support.percent.PercentRelativeLayout xmlns:app="

<View
    android:id="@+id/relative_top"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_alignParentTop="true"
    android:background="#000000"
    app:layout_heightPercent="30%"
    app:layout_widthPercent="100%" />

<android.support.percent.PercentFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/relative_middle"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_below="@+id/relative_top"
    android:background="#0000ff"
    app:layout_heightPercent="40%"
    app:layout_widthPercent="50%">

    <View
        android:id="@+id/frame_0"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#00ffff"
        app:layout_heightPercent="25%"
        app:layout_widthPercent="75%"
        app:layout_marginTopPercent="75%"
        app:layout_marginLeftPercent="25%"/>

    <View
        android:id="@+id/frame_1"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#ffff00"
        app:layout_heightPercent="75%"
        app:layout_widthPercent="25%" />
</android.support.percent.PercentFrameLayout>

<View
    android:id="@+id/relative_bottom"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_below="@id/relative_middle"
    android:background="#00ff00"
    app:layout_heightPercent="30%"
    app:layout_widthPercent="100%" />

</android.support.percent.PercentRelativeLayout> </RelativeLayout></pre>

```

支持屬性

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!