android layout 按比例布局的代碼
為了創(chuàng)建比例大小的子View,可以將LinearLayout的寬度和高度設為fill_parent, 而將子View的寬度或是高度設為0,然后為子View設置不同權重(weight) ,這樣子View的大小就會權值成比例。
本例使用橫向LinearLayout,LinearLayout的android:layout_width=”match_parent”,表示將使用整個屏幕寬度。
對于LinearLayout的幾個子View,將它們的寬度都定義為0,android:layout_width=”0dip”,然后使用layout_weight 為每個View指定寬度比例,本例為每個TextView都使用了相同的權值,因此四個TextView將會有相同的寬度。這樣對于那些顯示文字比較長的TextView的高度就變?yōu)槎嘈小?BR>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”android:orientation=”horizontal”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”>
<TextView
android:background=”@drawable/red”
android:layout_width=”0dip”
android:layout_height=”match_parent”
android:layout_weight=”1″
android:text=”@string/linear_layout_7_small”/>
<TextView
android:background=”@drawable/green”
android:layout_width=”0dip”
android:layout_height=”match_parent”
android:layout_weight=”1″
android:text=”@string/linear_layout_7_big”/>
<TextView
android:background=”@drawable/blue”
android:layout_width=”0dip”
android:layout_height=”match_parent”
android:layout_weight=”1″
android:text=”@string/linear_layout_7_small” />
<TextView
android:background=”@drawable/yellow”
android:layout_width=”0dip”
android:layout_height=”wrap_content”
android:layout_weight=”1″
android:text=”@string/linear_layout_7_wrap”/>
</LinearLayout>
- Android自定義View實現(xiàn)垂直時間軸布局
- Android中RecyclerView布局代替GridView實現(xiàn)類似支付寶的界面
- android動態(tài)加載布局文件示例
- android Activity相對布局的使用方法
- Android實現(xiàn)輸入法彈出時把布局頂上去和登錄按鈕頂上去的解決方法
- Android TabLayout(選項卡布局)簡單用法實例分析
- Android布局——Preference自定義layout的方法
- Android應用借助LinearLayout實現(xiàn)垂直水平居中布局
- android LinearLayout和RelativeLayout組合實現(xiàn)精確布局方法介紹
- Android實現(xiàn)Z軸布局效果
相關文章
Android編程實現(xiàn)為ListView創(chuàng)建上下文菜單(ContextMenu)的方法
這篇文章主要介紹了Android編程實現(xiàn)為ListView創(chuàng)建上下文菜單(ContextMenu)的方法,簡單分析了上下文菜單的功能及ListView創(chuàng)建上下文菜單(ContextMenu)的具體步驟與相關操作技巧,需要的朋友可以參考下2017-02-02Android?IdleHandler基本使用及應用案例詳解
這篇文章主要為大家詳細介紹了Android?IdleHandler的基本使用及應用案例,文中的示例代碼講解詳細,具有一定的參考價值,需要的可以參考一下2022-10-10java,Android:在eclipse中的快捷鍵(經典收藏)
下面的快捷鍵是常用的,本人就本身喜好且常用的收拾一下,現(xiàn)在曬出來與大家分享,感興趣的朋友可以了解小哦2013-01-01Android使用Scroll+Fragment仿京東分類效果
這篇文章主要為大家詳細介紹了Android使用Scroll+Fragment仿京東分類效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-02-02