简体   繁体   中英

Trying to set Drawable android:topLeftRadius, android:bottomLeftRadius but the view is different on different devices

I am trying to use drawable XML file as a button background. I want to achieve

在此处输入图片说明

But when I write that code:

<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>

I get that shape on phone:

在此处输入图片说明

When I changed code to:

<corners
        android:topLeftRadius="@dimen/button_radius"
        android:topRightRadius="0dp"
        android:bottomLeftRadius="@dimen/button_radius"
        android:bottomRightRadius="0dp"/>

I got the shape that I what but on tablets shape is not that I want. Any one could give me an advice what could be done?

I use this same shape in my app but with drawable like this:

<?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>

I use it in a LinearLayout with clickable set as TRUE, and works just perfect in every single device I have tested.

hope it helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM