Android:百分比布局

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>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容