[英]Ring Drawable on pre 5.1 android
我是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();
上面的代碼可以正常工作,但問題是它只能在5.1以下使用。我無法在5.1以上的版本中獲得任何環形。出問題的是該代碼需要修改,請幫忙!!
要為較舊的android版本創建環形,您可以定義帶有彩色筆觸的透明圓圈。 環是筆畫本身:
<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" />
或無xml方式:
GradientDrawable shape = new GradientDrawable();
shape.setColor(Color.Transparent);
shape.setStroke(20, Color.White);
嘗試從此處使用此代碼: 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.