詳解Android中weight的使用方法
android中對(duì)weight的學(xué)習(xí)可以說(shuō)是必須的,如果UI布局僅僅使用dp與sp等等,會(huì)讓布局顯得極度不靈活,畢竟各個(gè)手機(jī)屏幕大小不同,更別說(shuō)是還有ipad之類(lèi)的了,所以也是同做本人近期做的一個(gè)小UI來(lái)分享一下weight的使用。


左邊是各個(gè)屏幕的顯示效果,右邊是1080*1920屏幕的具體顯示效果??梢钥吹?,不管屏幕如何變化,使用weight的布局中總是填充滿(mǎn)屏幕的,至于美觀效果就不說(shuō)了,直接上代碼。
小編使用的android studio,eclipse用戶(hù)直接復(fù)制肯定會(huì)有問(wèn)題,AS用戶(hù)直接復(fù)制修改一下中間的圖片便可以用啦。
<LinearLayout 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:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:background="#7EB345">
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:drawableLeft="@drawable/left_menu"
android:paddingLeft="17dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="某某科技大學(xué)"
android:textSize="25sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="@android:color/transparent"
android:text="登陸"
android:textColor="#fff"
android:textSize="20sp" />
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.5"
android:background="@drawable/school" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@mipmap/ic_launcher"
android:paddingTop="18dp"
android:text="校園新聞" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@mipmap/ic_launcher"
android:paddingTop="18dp"
android:text="學(xué)術(shù)公告" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@mipmap/ic_launcher"
android:paddingTop="18dp"
android:text="成績(jī)查詢(xún)" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@mipmap/ic_launcher"
android:paddingTop="18dp"
android:text="課表信息" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@mipmap/ic_launcher"
android:paddingTop="18dp"
android:text="圖書(shū)借閱" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@mipmap/ic_launcher"
android:paddingTop="18dp"
android:text="飯卡消費(fèi)" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@mipmap/ic_launcher"
android:paddingTop="18dp"
android:text="校園地圖" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@mipmap/ic_launcher"
android:paddingTop="18dp"
android:text="在線咨詢(xún)" />
<Button
android:id="@+id/neirongbuju"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@mipmap/ic_launcher"
android:paddingTop="18dp"
android:text="查看更多" />
</LinearLayout>
</LinearLayout>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。
相關(guān)文章
Android中使用socket使底層和framework通信的實(shí)現(xiàn)方法
native和framework的通信是通過(guò)jni,但是這一般只是framework調(diào)用native,native如果有消息要怎樣通知上層 呢?android中GSP模塊提供一種解決思路,但是實(shí)現(xiàn)有些復(fù)雜,這里介紹一種使用socket通信的方法可以使native和framework自由通信,感興趣的朋友一起看看吧2016-11-11
Android開(kāi)發(fā)事件處理的代碼如何寫(xiě)手摸手教程
這篇文章主要為大家介紹了Android開(kāi)發(fā)事件處理的代碼如何寫(xiě)手摸手教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
Android自定義View實(shí)現(xiàn)左右滑動(dòng)選擇出生年份
這篇文章主要介紹了Android自定義View實(shí)現(xiàn)左右滑動(dòng)選擇出生年份,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-06-06
Android內(nèi)存泄漏檢測(cè)工具LeakCanary
在Android的性能優(yōu)化中,內(nèi)存優(yōu)化是必不可少的點(diǎn),而內(nèi)存優(yōu)化最重要的一點(diǎn)就是解決內(nèi)存泄漏的問(wèn)題,在Android的內(nèi)存泄漏分析工具也不少,比如PC端的有:AndroidStudio自帶的Android?Profiler、MAT等工具;手機(jī)端也有,就是我們今天要介紹的LeakCanary2023-04-04
解決Eclipse啟動(dòng)出錯(cuò):Failed to create the Java Virtual Machine
這篇文章主要介紹了解決Eclipse啟動(dòng)出錯(cuò):Failed to create the Java Virtual Machine的相關(guān)資料,這里說(shuō)明出錯(cuò)原因及查找錯(cuò)誤和解決辦法,需要的朋友可以參考下2017-07-07
Android基礎(chǔ)知識(shí)之frame動(dòng)畫(huà)效果
Android基礎(chǔ)知識(shí)之tween動(dòng)畫(huà)效果,Android一共提供了兩種動(dòng)畫(huà),這篇文章主要介紹了Android動(dòng)畫(huà)效果之frame動(dòng)畫(huà),感興趣的小伙伴們可以參考一下2016-06-06
Android性能優(yōu)化之plt?hook與native線程監(jiān)控詳解
這篇文章主要為大家介紹了Android性能優(yōu)化之plt?hook與native線程監(jiān)控詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09

