android 用XML定義邊框,


只上下邊框有色

layer-list item內矩形shape疊加實現

xml繪制背景 layout_line.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 連框顏色值 -->
    <item>
        <shape>
            <solid android:color="#CCCCCC" />
        </shape>
    </item>
    <!-- 主體背景顏色值 -->
    <!-- 此處定義只有上下兩邊有邊框 高度為1像素-->
    <item
        android:bottom="1dp"
        android:top="1dp">
        <!--邊框里面背景顏色 白色-->
        <shape>
            <solid android:color="#ffffff" />
        </shape>
    </item>
</layer-list>

設置到控件

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:background="@drawable/layout_line"
        android:orientation="horizontal" >

效果圖:

 根據需要,修改:

android:top="1dp"
android:left="1dp"
android:right="1dp"
android:bottom="1dp"

顯示需要的邊框

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM