Android布局檔案經驗

來源:互聯網
上載者:User

標籤:android   c   style   class   blog   code   

1.父控制項中含有多個子控制項時,往往遵循長子優先的原則,即長子如果很大可能佔滿父空間,使次子們出局;

2.假設TableLayout有2行,其中一行未設定列間長度比例,而另一行設定了,則未設定行可能也會遵循設定行的列間長度比例;

3.在某個地區(如TableLayout中某個單元格)顯示某張超大的圖片,希望圖片總是自適應單元格而不是把單元格撐爆。解決方案:將單元格放在LinearLayout中,給LinearLayout設定android:layout_width="wrap_content"、android:orientation="horizontal",給單元格設定layout_weight屬性、不設定android:layout_width屬性。

<RelativeLayout 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:background="#ffffff">    <TableLayout        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_below="@+id/include1"        android:background="#dedcd2"        android:stretchColumns="*" >        <TableRow            android:layout_margin="0.5dip"            android:background="#dedcd2" >            <LinearLayout                android:layout_width="wrap_content"                android:layout_height="30dp"                android:orientation="horizontal" >                <TextView                    android:layout_height="fill_parent"                    android:layout_margin="1dip"                    android:layout_weight="2"                    android:background="#ffffff"                    android:text=""                    android:textSize="12dp"                    android:textStyle="bold" />                <TextView                    android:layout_height="fill_parent"                    android:layout_margin="1dip"                    android:layout_weight="2"                    android:background="#ffffff"                    android:text=""                    android:textSize="12dp"                    android:textStyle="bold" />                                <!-- @drawable/right 為超大圖片 -->                <ImageView                    android:layout_height="fill_parent"                    android:layout_margin="1dip"                    android:layout_weight="1"                    android:src="@drawable/right" />                <TextView                    android:layout_height="fill_parent"                    android:layout_margin="1dip"                    android:layout_weight="2"                    android:background="#ffffff"                    android:text=""                    android:textSize="12dp"                    android:textStyle="bold" />            </LinearLayout>        </TableRow>    </TableLayout></RelativeLayout>


聯繫我們

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