【问题标题】:change drawable shape parameter programmatically以编程方式更改可绘制形状参数
【发布时间】:2015-07-14 17:43:20
【问题描述】:

我想制作环形加载效果,为此我必须更改 dashWidth 值。

我想以编程方式进行。

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

【问题讨论】:

  • 那看看是什么Drawable,可以通过调用View#getBackground()获取背景Drawable
  • 是的,但是如何更改参数?我找不到破折号宽度的设置器!
  • 那是什么样的 Drawable?
  • 它是 xml 文件中的椭圆形
  • 不是 GradientDrawable?你确定吗?

标签: android android-drawable xml-drawable


【解决方案1】:

作为 psink 可悲的是,可以从笔划访问 dashGap 和 dashWidth 属性。 在将背景对象转换为 GradientDrawable 后,我只是在背景对象上使用了 setStroke 方法

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多