PercentLayout的固定比例

jopen 8年前發布 | 7K 次閱讀 Android開發 移動開發

PercentLayout是百分比控件, 使用百分比屬性創建控件. 除了常用的百分比, 也可以使用固定比例進行布局(aspect ratio). Percent相關Layout包括: PercentFrameLayout \ PercentRelativeLayout.

效果

Gradle依賴

compile 'com.android.support:percent:23.1.0'

Layout布局, 提供寬度和比例, 自動適配高度.

    <android.support.percent.PercentRelativeLayout  android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/main_text">

        <ImageView  android:layout_width="0dp" android:layout_height="0dp" android:background="#FF1493" app:layout_aspectRatio="@fraction/header_aspectRatio" app:layout_widthPercent="50%"/>

    </android.support.percent.PercentRelativeLayout>

比例的資源文件, fractions.xml.

<resources>
    <item name="header_aspectRatio" type="fraction">178%</item>
</resources>

178%的含義是16:9.

參考

OK, 可以通過比例, 更好的設置百分比控件.

來自: http://blog.csdn.net//caroline_wendy/article/details/50107829

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