2014年7月11日 星期五

LinearLayout比重方式


設計Android App 有個麻煩之處就是,使用android系統的手機都有很多不同大小的畫面,所以在設計時我們必須使用activity或xml檔,在裡頭設定頁面的屬性。例如以上這個方式是使用LinearLayout比重的方式來設計,例如一下程式碼,有發現我的android:layout_height="0dp" 還有android:layout_weight="1",height是表示我們需要改變的高度,然後使用weight可以讓我們來設計佔整個畫面的多少。例如兩個weight都是1, 就是1/2的意思。當然如果我們要改變寬度就是用一樣的方式把width改變。(有寫錯或有更好方法的可以告訴小弟 :) )

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical" >
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical" >
        </LinearLayout>

    </LinearLayout>

沒有留言:

張貼留言