Android weight权重适配

来源:互联网 发布:趣发现是什么软件 编辑:程序博客网 时间:2024/05/24 22:41

手机的屏幕适配,有很多种方式,其中一种就是权重适配。

效果图:


第一行比例:1:1

第二行比例:1:1:1

示例代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context=".MainActivity" >    <LinearLayout        android:layout_width="match_parent"        android:layout_height="100dp"        android:orientation="horizontal" >        <TextView            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:layout_weight="1"            android:background="#f00" />        <TextView            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:layout_weight="1"            android:background="#0f0" />    </LinearLayout>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="100dp"        android:orientation="horizontal"        android:weightSum="3" >        <TextView            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:layout_weight="1"            android:background="#0f0" />        <TextView            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:layout_weight="1"            android:background="#f00" />    </LinearLayout></LinearLayout>


0 0