欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解Android中weight的使用方法

 更新時間:2016年01月11日 09:20:43   作者:xu佳佳  
這篇文章主要向大家介紹了詳解Android中weight的使用方法,感興趣的小伙伴們可以參考一下

android中對weight的學習可以說是必須的,如果UI布局僅僅使用dp與sp等等,會讓布局顯得極度不靈活,畢竟各個手機屏幕大小不同,更別說是還有ipad之類的了,所以也是同做本人近期做的一個小UI來分享一下weight的使用。

    

  

左邊是各個屏幕的顯示效果,右邊是1080*1920屏幕的具體顯示效果??梢钥吹?,不管屏幕如何變化,使用weight的布局中總是填充滿屏幕的,至于美觀效果就不說了,直接上代碼。

小編使用的android studio,eclipse用戶直接復制肯定會有問題,AS用戶直接復制修改一下中間的圖片便可以用啦。

<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="某某科技大學" 
      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="學術公告" /> 
 
    <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="成績查詢" /> 
  </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="圖書借閱" /> 
 
    <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="飯卡消費" /> 
  </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="在線咨詢" /> 
 
    <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> 

以上就是本文的全部內容,希望對大家的學習有所幫助。

相關文章

  • Android TextView跑馬燈效果實現方法

    Android TextView跑馬燈效果實現方法

    這篇文章主要介紹了Android TextView跑馬燈效果實現方法,涉及Android布局文件中相關屬性的設置技巧,非常簡單實用,需要的朋友可以參考下
    2016-01-01
  • android實現多線程下載文件(支持暫停、取消、斷點續(xù)傳)

    android實現多線程下載文件(支持暫停、取消、斷點續(xù)傳)

    本篇文章主要介紹了androids實現多線程下載文件,主要包括暫停、取消、斷點續(xù)傳等功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-02-02
  • Android實現簡單圖庫輔助器

    Android實現簡單圖庫輔助器

    這篇文章主要為大家詳細介紹了Android實現簡單圖庫輔助器的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • Android 存儲路徑選擇方法

    Android 存儲路徑選擇方法

    今天小編就為大家分享一篇Android 存儲路徑選擇方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • android實現橫屏的代碼及思路

    android實現橫屏的代碼及思路

    android實現橫屏的代碼及思路,需要的朋友可以參考一下
    2013-05-05
  • Android實現3秒鐘自動關閉界面

    Android實現3秒鐘自動關閉界面

    這篇文章主要為大家詳細介紹了Android實現3秒鐘自動關閉界面,以支付成功為例,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-02-02
  • Android四大組件之BroadcastReceiver詳解

    Android四大組件之BroadcastReceiver詳解

    今天小編就為大家分享一篇關于Android四大組件之BroadcastReceiver詳解,小編覺得內容挺不錯的,現在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • XRecyclerView實現下拉刷新、滾動到底部加載更多等功能

    XRecyclerView實現下拉刷新、滾動到底部加載更多等功能

    這篇文章主要為大家詳細介紹了XRecyclerView實現下拉刷新、滾動到底部加載更多等功能,以及添加header功能的RecyclerView,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • Android中invalidate()和postInvalidate() 的區(qū)別及使用方法

    Android中invalidate()和postInvalidate() 的區(qū)別及使用方法

    Android中實現view的更新有兩組方法,一組是invalidate,另一組是postInvalidate,其中前者是在UI線程自身中使用,而后者在非UI線程中使用。本文給大家介紹Android中invalidate()和postInvalidate() 的區(qū)別及使用方法,感興趣的朋友一起學習吧
    2016-05-05
  • Android中Textview和圖片同行顯示(文字超出用省略號,圖片自動靠右邊)

    Android中Textview和圖片同行顯示(文字超出用省略號,圖片自動靠右邊)

    Android中Textview和圖片同行顯示,文字超出用省略號顯示,圖片自動靠右邊。看到這個問題本來認為是一個很正常的需求,看起來很簡單,但是做起來卻遇到了很蛋疼的問題,怎么搞的都不行,堵了很長時間,下面說一下解決的方案,希望遇到這樣問題的朋友可以使用。
    2016-12-12

最新評論