LayerDrawable
<layer-list> 標簽可是設置LayerDrawable,一種有層次的Drawable疊加效果,<layer-list> 可以包含多個 <item>標簽,
每個 <item>代表一個Drawable。<item>可以通過left、right、top、bottom設置左右上下的偏移量,<item>可以應用一個圖片,也可以是一個shape
我們來模仿實現微信的聊天輸入框:
先設置綠色的背景:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/holo_green_light" />
</shape>
</item>
</layer-list>

再疊加一層白色,留出側面綠色線條的高度:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/holo_green_light" />
</shape>
</item>
<item android:bottom="8dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />
</shape>
</item>
</layer-list>

再鋪上一層白色,覆蓋已經設置好的背景,留出底部和側面的線條,中間的一層其實就是為了留出兩邊的綠色線框的高度:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/holo_green_light" />
</shape>
</item>
<item android:bottom="8dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />
</shape>
</item>
<item
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:shape="rectangle">
<shape>
<solid android:color="@android:color/white" />
</shape>
</item>
</layer-list>
以上所述是小編給大家介紹的Android 使用<layer-list>實現微信聊天輸入框,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。