美文网首页
Android:百分比布局

Android:百分比布局

作者: lovingMJ | 来源:发表于2017-02-14 18:33 被阅读0次

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>

相关文章

网友评论

      本文标题:Android:百分比布局

      本文链接:https://www.haomeiwen.com/subject/mjqfwttx.html