简体   繁体   中英

change drawable shape parameter programmatically

iam looking to make a ring loading effect and to do that i have to change the dashWidth value.

I want to do that programmatically.

<?xml version="1.0" encoding="utf-8"?>
<shape
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="oval">

  <stroke
    android:width="3dp"
    android:color="#8FFFFFFF" 
    android:dashWidth="304dp"
    android:dashGap="500dp"/>

  <size 
    android:width="100dp"
    android:height="100dp"/>
</shape>

As psink sad it's possible to access the dashGap and dashWidth attribute from the stroke. I just used the setStroke method on the background object after casting it to a GradientDrawable

GradientDrawable background = (GradientDrawable)backgroundContainer.getBackground();
background.setStroke(3, Color.WHITE, 50, 500);

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