android LinearLayout 适配

在android开发开发中使用LinearLayout来进行布局的安排,现在将其中的相关的适配问题总结:

1、使用LinearLayout的layout_weight和wrap_content进行配合使用,当在进行页面的适配设计的时候使用比例,无可争议是最好的方式就是按照比例进行页面的布局,这种方式在一定范围可以避免页面布局出现大的错乱,还有一点我感觉使用fragment进行页面的重构也很重要,将大的页面进行分割,分割成小的模块,这样不仅可以提高代码的重用更可以降低UI设计困难,Layout——weight是按照同一级的比例进行分配的,子模块是没有影响,还有一点就是fragment进行碎片化以后更加可以提高代码的可扩展性还有代码自身的适应能力

layout_weight  叫做剩余权重(很有才的名字)

下面是测试的一下代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">


    <LinearLayout
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:color/holo_red_dark"
            android:text="111"
            android:textSize="20sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:background="@android:color/holo_green_light"
            android:text="222"
            android:textSize="20sp" />

    </LinearLayout>


    <LinearLayout
        android:layout_weight="2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:color/holo_red_dark"
            android:text="111"
            android:textSize="20sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:background="@android:color/holo_green_light"
            android:text="222"
            android:textSize="20sp" />


        <LinearLayout
            android:layout_weight="2"
            android:background="@color/black"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"></LinearLayout>

    </LinearLayout>


</LinearLayout>
下面是实现的效果




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值