Android:百分比布局

2017-02-14  本文已影响0人  lovingMJ

1.添加compile 'com.android.support:percent:25.1.1'支持库依赖,版本要一致

第一步添加percent依赖.png
2.写四个Button控件,平均分配主屏幕
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
第二步添加四个按钮.png
3.最终效果
最终效果.png
4.xml文件代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentFrameLayout     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">
    <Button
        android:text="Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left|top"
        app:layout_widthPercent="50%"
        app:layout_heightPercent="50%"
        android:id="@+id/button" />
    <Button
        app:layout_widthPercent="50%"
        app:layout_heightPercent="50%"
        android:text="Button"
        android:layout_gravity="left|bottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button2" />
    <Button
        app:layout_widthPercent="50%"
        app:layout_heightPercent="50%"
        android:text="Button"
        android:layout_gravity="right|top"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button3" />
    <Button
        app:layout_widthPercent="50%"
        app:layout_heightPercent="50%"
        android:text="Button"
        android:layout_gravity="right|bottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button4" />
</android.support.percent.PercentFrameLayout>
上一篇 下一篇

猜你喜欢

热点阅读