![](/img/trans.png)
[英]How to set TopLeftRadius and BottomLeftRadius for a GradientDrawable programmatically in Android
[英]android:topLeftRadius overriding other corners
解決方案:好吧,這是我的模擬器和蝕布局編輯器。 在真正的電話上,它可以正常工作:(
題:
角落的android:topLeftRadius會覆蓋topRight,bottomRight和bottomLeft。
因此,當我要對右側進行圓角處理時,左側應平方,但兩側均應平方。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#F000" />
<stroke
android:width="1px"
android:color="#BB000000" />
<padding
android:bottom="7dp"
android:left="10dp"
android:right="10dp"
android:top="7dp" />
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="0dp"
android:topRightRadius="10dp" />
<gradient
android:angle="90"
android:centerColor="#00004C"
android:endColor="#000099"
android:startColor="#000000"
android:type="linear" />
</shape>
我只是在按鈕的xml中調用它。
android:background =“ @ drawable / button_layout”
您忘記了在屬性周圍需要一個<shape>
。 該代碼對我有用:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#F000" />
<stroke
android:width="1px"
android:color="#BB000000" />
<padding
android:bottom="7dp"
android:left="10dp"
android:right="10dp"
android:top="7dp" />
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="0dp"
android:topRightRadius="10dp" />
<gradient
android:angle="90"
android:centerColor="#00004C"
android:endColor="#000099"
android:startColor="#000000"
android:type="linear" />
</shape>
這可能與3.0之前的Android版本中的錯誤有關(請參閱https://code.google.com/p/android/issues/detail?id=9161 )
您可以通過為不同的api版本使用單獨的可繪制文件夾來解決此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.