關於Android LinearLayout添加分隔線的方法

來源:互聯網
上載者:User

標籤:android   style   blog   http   io   ar   color   使用   sp   

目前瞭解的辦法有兩個:1、自訂一個view當作分隔線;2、使用高版本的分隔線屬性

一、在需要添加分隔線的地方,添加一個view,比如ImageView,TextView等都可以,如代碼,關鍵是設定高度要小,寬度要合適

<ImageView           android:layout_width="fill_parent"          android:layout_height="1dp"          android:background="#00FF00"          /> 


二、就是設定LinearLayout的分隔線屬性,參數說明:

  android:showDividers=""    屬性有4個值:  none      不顯示分隔線(預設值);  beginning   在開始處顯示分隔線;  end      在結尾處顯示分隔線;  middle       在每兩個組件間顯示分隔線:  除了設定android:showDividers屬性外,還要設定android:divider屬性,該屬性工作表示分隔線的映像Drawable(該圖片的高度就是分隔線的高度,所以要細的

代碼如下:

android:showDividers="end"  android:divider="@drawable/mydivider" 

也可以不用圖片,自己定義一個shape

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <size android:width="1dp" /> <solid android:color="#0000FF00" /></shape>

使用時,直接把這個xml檔案當圖片一樣設定android:divider就好了

 

關於Android 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.