我的Android進階之旅------>怎樣在多個LinearLayout中加入分隔線

來源:互聯網
上載者:User

標籤:imageview   ora   detail   支援   圖片   port   ack   normal   com   


假設要適合於全部的Android版本號碼,能夠在多個LinearLayout放置用於顯示分隔線的View。

比如,放一個ImageView組件。然後將其背景設為分隔線的顏色或映像,分隔線View的定義代碼例如以下:

<ImageView           android:layout_width="fill_parent"          android:layout_height="1dp"          android:background="#ffffff"          />  
效果例如以下:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" style="font-size:24px">


在Android3.0及以上版本號碼,LinearLayout支援直接顯示分隔線。設定<LinearLayout>標籤的android:showDividers屬效能夠再LinearLayout的對應位置顯示分隔線。假設有多個LinearLayout,顯示效果和在LinearLayout之間加分隔線是一樣的。

android:showDividers屬效能夠設定例如以下4個值:
none:不顯示分隔線;
beginning:在LinearLayout的開始處顯示分隔線;
end:在Linearlayout的結尾處顯示分隔線;
middle:在LinearLayout中的每兩個組件間顯示分隔線:
除了須要設定android:showDividers屬性外,還要設定android:divider屬性。該屬性工作表示分隔線的映像,須要一個Drawable ID

android:divider="@drawable/shape"<!--切割線圖片-->  android:showDividers="middle|beginning|end|none" <!--切割線位置-->  

1、android:divider="@drawable/shape"

drawable能夠是圖片檔案,也能夠是xml繪製的shape。

切割線假設是圖片那就直接使用圖片即可,假設要使用顏色就必須使用shape來顯示,直接使用顏色或Color是沒實用的 
使用shape的時候要注意設定size屬性不設定寬高切割線就不會顯示出來,假設使用line那填充顏色僅僅能使用stroke來顯示顏色

使用shape的時候一定要加入<size> 比如:

[java] view plaincopy
  1. <?

    xml version="1.0" encoding="utf-8"?>  

  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <solid android:color="@color/account_line" />  
  4.     <size android:height="1px" />  
  5. </shape>  

2、android:showDividers = "middle|end|beginning|none"

middle 在每一項中間加入切割線

end 在總體的最後一項加入切割線

beginning 在總體的最上方加入切割線

none 無


在Java代碼中能夠使用以下兩個方法設定android:showDividers和android:divider

linearLayout.setShowDividers:設定android:showDividers屬性。

linearLayout.setDividerDrawable: 設定android:divider屬性。


PS:能夠參考

Android 自己定義控制項 優雅實現元素間的切割線 (支援3.0下面)

     地址:http://blog.csdn.net/lmj623565791/article/details/42407923

 

 




                            ====================================================================================

  歐陽鵬  歡迎轉載,與人分享是進步的源泉!

  轉載請保留原文地址:http://blog.csdn.net/ouyang_peng

====================================================================================

 


我的Android進階之旅------&gt;怎樣在多個LinearLayout中加入分隔線

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.