【安卓】讓子項目超出容器限制、!如何?更靈活的容器布局、!

來源:互聯網
上載者:User

標籤:android   linearlayout   relativelayout   布局   

安卓中LinearLayout是用得最得心應手的容器,但有時候貌似不盡人意,其實安卓中的容器真的很靈活。!

1.讓子項目超出容器限制。初步想象一下,貌似子項目給定margin為負數即可超出,但事實卻是超出容器部分沒有繪製出來。

其實是可以繪製出來的,紅色容器的容器(注意是紅色控制項的容器,不是紅色容器自己)給定android:clipChildren="false"即可,該參數預設為true,即其內元素會被其容器裁剪,注意之所以是紅色容器的容器,是因為綠色按鈕突出部分已不在紅色容器繪製範圍內了,而屬於紅色容器的容器。

     


2.下面這種布局,按傳統模式一般最外層用LinearLayout,裡面再套RelativeLayout,以及各種噁心的排位。

其實可以來得更爽快一點,一個LinearLayout容器搞定。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#ffffff"    android:clipToPadding="false"    android:orientation="horizontal"    android:padding="10dp" >    <TextView        android:id="@+id/tvVIP"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="VIP1"        android:textColor="#000000"        android:textStyle="bold" />    <EditText        android:id="@+id/et"        android:layout_width="0dp"        android:layout_height="wrap_content"        android:layout_weight="1"        android:paddingRight="20dp"        android:text="1000" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginLeft="-20dp"        android:text="元" />    <Button        android:id="@+id/btnDel"        android:layout_width="wrap_content"        android:layout_height="20dp"        android:layout_marginLeft="-15dp"        android:layout_marginTop="-10dp" /></LinearLayout>





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.