android LinearLayout 适配

来源:互联网 发布:七上生物行知天下答案 编辑:程序博客网 时间:2024/06/05 04:08

在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>
下面是实现的效果




0 0
原创粉丝点击