当前位置: 代码迷 >> Android >> Android中元素按比例格局
  详细解决方案

Android中元素按比例格局

热度:10   发布时间:2016-04-28 06:50:59.0
Android中元素按比例布局

为了创建比例大小的子View,可以将LinearLayout的宽度和高度设为fill_parent, 而将子View的宽度或是高度设为0,然后为子View设置不同权重(weight) ,这样子View的大小就会权值成比例。

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"     >    <TextView        android:layout_width="0dp"        android:layout_height="match_parent"        android:layout_weight="1"        android:background="@color/orange" />    <TextView        android:layout_width="0dp"        android:layout_height="match_parent"        android:layout_weight="1"        android:background="@color/blue" />    <TextView        android:layout_width="0dp"        android:layout_height="match_parent"        android:layout_weight="1"        android:background="@color/coffee" />    <TextView        android:layout_width="0dp"        android:layout_height="match_parent"        android:layout_weight="1"        android:background="@color/yellow" /></LinearLayout>

?

效果图:

?

?

  相关解决方案