android layout 按比例布局的代碼
為了創(chuàng)建比例大小的子View,可以將LinearLayout的寬度和高度設(shè)為fill_parent, 而將子View的寬度或是高度設(shè)為0,然后為子View設(shè)置不同權(quán)重(weight) ,這樣子View的大小就會權(quán)值成比例。
本例使用橫向LinearLayout,LinearLayout的android:layout_width=”match_parent”,表示將使用整個屏幕寬度。
對于LinearLayout的幾個子View,將它們的寬度都定義為0,android:layout_width=”0dip”,然后使用layout_weight 為每個View指定寬度比例,本例為每個TextView都使用了相同的權(quán)值,因此四個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應(yīng)用借助LinearLayout實現(xiàn)垂直水平居中布局
- android LinearLayout和RelativeLayout組合實現(xiàn)精確布局方法介紹
- Android實現(xiàn)Z軸布局效果
相關(guān)文章
Android仿微信界面的導(dǎo)航以及右上角菜單欄效果
這篇文章主要介紹了Android仿微信界面的導(dǎo)航以及右上角菜單欄效果,具有很好的參考價值,希望對大家有所幫助,一起跟隨小編過來看看吧2018-05-05
一文理解Android系統(tǒng)中強指針的實現(xiàn)
因為Android中很多地方代碼是用C++編寫,為了能夠保證C++中指針能夠被正確的釋放,于是Android引入了其實在C++中已經(jīng)有的智能指針技術(shù)2021-10-10
Android加載大分辨率圖片到手機內(nèi)存中的實例方法
有些圖片的分辨率比較高,把它直接加載到手機內(nèi)存中之后,會導(dǎo)致堆內(nèi)存溢出的問題,下面就講解一下Android的堆內(nèi)存以及如何在Android應(yīng)用中加載一個高分辨率的圖片的方法2013-11-11
Android 實現(xiàn)不同字體顏色的TextView實現(xiàn)代碼
這篇文章主要介紹了Android 實現(xiàn)不同字體顏色的TextView實現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2017-05-05
Android 讓自定義TextView的drawableLeft與文本一起居中
本文主要介紹Android 自定義控件TextView顯示居中問題,在開發(fā)過程中經(jīng)常會遇到控件的重寫,這里主要介紹TextView的drawableLeft與文本一起居中的問題2016-07-07
Android開發(fā)之在程序中時時獲取logcat日志信息的方法(附demo源碼下載)
這篇文章主要介紹了Android開發(fā)之在程序中時時獲取logcat日志信息的方法,結(jié)合實例形式較為詳細的分析了實時獲取logcat日志的原理、步驟與相關(guān)實現(xiàn)技巧,并附帶相應(yīng)的demo源碼供讀者下載參考,需要的朋友可以參考下2016-02-02
Android自定義View實現(xiàn)繪制水波浪溫度刻度表
這篇文章主要為大家詳細介紹了Android如何利用自定義View實現(xiàn)一個水波浪溫度刻度表,文中的示例代碼講解詳細,感興趣的小伙伴可以嘗試一下2022-11-11
Android 自定義View之邊緣凹凸的優(yōu)惠券效果的開發(fā)過程
這篇文章主要介紹了Android 自定義View之邊緣凹凸的優(yōu)惠券效果,主要總結(jié)一下在自定義View的開發(fā)過程中需要注意的一些地方.需要的朋友可以參考下2018-03-03

