标签:
本文是看了鸿洋视频后的小结:
首先按照声明的尺寸分配,剩余的空间再按照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:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal">
    <TextView
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:background="#e1d611"
        android:gravity="center"
        android:text="我是老大我是老大我是老大"
        android:textColor="#ffffff"
        android:visibility="gone" />
    <TextView
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:background="#09c0f2"
        android:gravity="center"
        android:text="我是老二"
        android:textColor="#ffffff" />
    <TextView
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:background="#074bc1"
        android:gravity="center"
        android:text="我是老三"
        android:textColor="#ffffff"
        android:visibility="gone" />
</LinearLayout> 
在父控件里添加代码:
  android:baselineAligned="false" 
在父控件里添加
android:weightSum="2"代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:baselineAligned="false"
    android:gravity="center"
    android:orientation="horizontal"
    android:weightSum="2">
    <TextView
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:background="#09c0f2"
        android:gravity="center"
        android:text="我是老二"
        android:textColor="#ffffff" />
</LinearLayout>标签:
原文地址:http://blog.csdn.net/pengkv/article/details/50487072