W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
在Drawable中創(chuàng)建圓角
要在Drawable中實(shí)現(xiàn)圓角,可以使用當(dāng)前未記錄的<shape>
標(biāo)簽。
這個(gè)標(biāo)簽需存在于 /res/drawable
目錄的一個(gè)文件中。
以下代碼顯示了如何使用<shape>
標(biāo)簽在名為 /res/drawable/my_rounded_rectangle.xml
的文件中定義圓角矩形。
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#f0600000"/> <stroke android:width="3dp" color="#ffff8080"/> <corners android:radius="13dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape>
然后,你可以使用此可繪制資源作為之前文本視圖的背景,例如。
GradientDrawable roundedRectangle = (GradientDrawable) activity.getResources().getDrawable(R.drawable.my_rounded_rectangle); textView.setBackgroundDrawable(roundedRectangle);
最后,drawable子目錄中的位圖圖像解析為BitmapDrawable
類(lèi)。drawable資源值,如一個(gè)矩形,解析為ColorDrawable
。
帶有< shape>
標(biāo)簽的XML文件解析為 GradientDrawable
。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: