简体   繁体   English

在5.1之前的android上可绘制戒指

[英]Ring Drawable on pre 5.1 android

I'm new to android i'am creating an app where I include an ring shape inside one layout for that i'm using the below code: 我是Android的新手,我正在创建一个应用,其中使用以下代码在一个布局内添加环形形状:

Display display = getWindowManager().getDefaultDisplay();
              Point size = new Point();
              display.getSize(size);
              int width = size.x;
              int height = size.y;


              Log.e("(width/2)-70", (width/2)-70+"%%%");
              RingDrawable ring = new RingDrawable(0,(width/2)-70 , 0, 0);
               ring.setColor(Color.parseColor("#0f000000"));

               backgroundSpeaker.setBackground(ring);
             //  backgroundSpeaker.setAnimation(zoom);
               backgroundSpeaker.invalidate();
               speaker_layout.invalidate();

above code working fine but the issue is it's work only below 5.1.i'am not able to get any ring shape which in above 5.1 version.What went wrong is the code needs to be modified,Please help!!.Thanks in advance 上面的代码可以正常工作,但问题是它只能在5.1以下使用。我无法在5.1以上的版本中获得任何环形。出问题的是该代码需要修改,请帮忙!!

To create a ring shape for older android versions, you can define a transparent circle with a colored stroke. 要为较旧的android版本创建环形,您可以定义带有彩色笔触的透明圆圈。 The ring is the stroke itself: 环是笔画本身:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >

<solid android:color="@color/transparent"/>
<stroke android:color="#fff" android:width="5dp" />

or the xml-less way: 或无xml方式:

GradientDrawable shape = new GradientDrawable();
shape.setColor(Color.Transparent);
shape.setStroke(20, Color.White);

Try using this one from here: https://github.com/MinaSamy/DailySelfie/blob/master/app/src/main/res/drawable/progress_drawable.xml 尝试从此处使用此代码: https : //github.com/MinaSamy/DailySelfie/blob/master/app/src/main/res/drawable/progress_drawable.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="100"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360" >

    <shape
        android:innerRadius="20dp"
        android:shape="ring"
        android:thickness="4dp"
        android:useLevel="false" >
        <size
            android:height="48dp"
            android:width="48dp" />

        <gradient
            android:centerColor="@color/colorAccent"
            android:centerY="0.5"
            android:endColor="#00FFFFFF"
            android:startColor="@color/colorPrimaryDark"
            android:type="sweep"
            android:useLevel="false" />
    </shape>

</rotate>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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