layout_weight屬性圖解

來源:互聯網
上載者:User

layout_weight屬性圖解
layout_height的作用:

首先按照聲明的尺寸分配,剩餘的空間再按照layout_weight進行分配
一平均分配:


代碼:

<code class="hljs xml"><!--{cke_protected}{C}%3C!%2D%2D%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%2D%2D%3E--><linearlayout android:gravity="center" android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="horizontal" xmlns:android="http://schemas.android.com/apk/res/android">    <textview android:background="#e1d611" android:gravity="center" android:layout_height="50dp" android:layout_weight="1" android:layout_width="0dp" android:text="我是老大我是老大我是老大" android:textcolor="#ffffff" android:visibility="gone">    <textview android:background="#09c0f2" android:gravity="center" android:layout_height="50dp" android:layout_weight="1" android:layout_width="0dp" android:text="我是老二" android:textcolor="#ffffff">    <textview android:background="#074bc1" android:gravity="center" android:layout_height="50dp" android:layout_weight="1" android:layout_width="0dp" android:text="我是老三" android:textcolor="#ffffff" android:visibility="gone"></textview></textview></textview></linearlayout></code>
二平均且對齊:


在父控制項裡添加代碼:

  android:baselineAligned="false"
三單個分配比例:


在父控制項裡添加

android:weightSum="2"

代碼:

<code class="hljs xml"><!--{cke_protected}{C}%3C!%2D%2D%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%2D%2D%3E--><linearlayout android:baselinealigned="false" android:gravity="center" android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="horizontal" android:weightsum="2" xmlns:android="http://schemas.android.com/apk/res/android">    <textview android:background="#09c0f2" android:gravity="center" android:layout_height="50dp" android:layout_weight="1" android:layout_width="0dp" android:text="我是老二" android:textcolor="#ffffff"></textview></linearlayout></code>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.