標籤: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
- <?
xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android">
- <solid android:color="@color/account_line" />
- <size android:height="1px" />
- </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進階之旅------>怎樣在多個LinearLayout中加入分隔線