![](/img/trans.png)
[英]How to set TopLeftRadius and BottomLeftRadius for a GradientDrawable programmatically in Android
[英]Trying to set Drawable android:topLeftRadius, android:bottomLeftRadius but the view is different on different devices
我试图将可绘制XML文件用作按钮背景。 我想实现
但是当我编写该代码时:
<shape android:shape="rectangle">
<corners
android:topLeftRadius="@dimen/button_radius"
android:topRightRadius="0dp"
android:bottomLeftRadius="0dp"
android:bottomRightRadius="@dimen/button_radius"/>
<stroke
android:width="@dimen/button_stroke_width"
android:color="@color/colorBlack"/>
<gradient
android:angle="-90"
android:startColor="@color/colorLightPurple"
android:endColor="@color/colorDeepPurple" />
</shape>
我在电话上看到了这个形状:
当我将代码更改为:
<corners
android:topLeftRadius="@dimen/button_radius"
android:topRightRadius="0dp"
android:bottomLeftRadius="@dimen/button_radius"
android:bottomRightRadius="0dp"/>
我得到了我想要的形状,但在平板电脑上却不是我想要的形状。 任何人都可以给我一个建议,怎么办?
我在我的应用程序中使用了相同的形状,但使用了drawable,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/log_btn_cancel"/>
<corners
android:radius="1dp"
android:topLeftRadius="10dp"
android:topRightRadius="0dp"
android:bottomLeftRadius="0dp"
android:bottomRightRadius="10dp"/>
</shape>
我在可点击设置为TRUE的LinearLayout中使用它,并且在我测试过的每个设备中都可以完美地工作。
希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.