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

