我试图在 xml 中自定义一个不确定的进度条,但我找不到一种方法来调整边缘。我从 SDK 资源中找到了默认的 xml 可绘制对象,但它们只是引用 PNG 而没有提及形状。
这是来自 SDK 资源的默认 xml:
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/progressbar_indeterminate1" android:duration="200" />
<item android:drawable="@drawable/progressbar_indeterminate2" android:duration="200" />
<item android:drawable="@drawable/progressbar_indeterminate3" android:duration="200" />
</animation-list>
progressbar_indeterminate1
、2 和 3 只是方形 PNG,但它始终显示带有圆边的进度条。
我已经尝试创建一个形状并使用 PNG 作为背景:
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:drawable="@drawable/progressbar_indeterminate1"
android:duration="200">
<shape>
<corners android:radius="0dp" />
</shape>
</item>
</animation-list>
但它不会改变形状。我会发布图片,但我还没有足够的声誉。 我错过了什么?感谢您的帮助。
最佳答案
我刚遇到同样的问题,似乎使用 XML 设置的不确定可绘制对象有圆角。如果您需要正方形(或可能任何其他)边缘,那么您需要使用代码设置不确定的可绘制对象:
// line below is needed to have sharp corners in the indeterminate drawable,
// ProgressBar when parsing indeterminate drawable from XML sets rounded corners.
progressBar.setIndeterminateDrawable(context.getResources().getDrawable(R.drawable.progressbar_indeterminate));
然后是我使用的 progressbar_indeterminate 示例:
<?xml version="1.0" encoding="UTF-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/progress_2b" android:duration="100" />
<item android:drawable="@drawable/progress_1b" android:duration="100" />
</animation-list>
我需要重复图像,所以我创建了 progress_1b(和 2b),如下所示:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/progress_1"
android:tileMode="repeat" >
</bitmap>`
其中 drawable/progress_1 是我想重复作为不确定进度条背景的真实图像。
这个解决方案对我有用。
关于android - android中的方形边缘不确定进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16499346/