android中的方形边缘不确定进度条

我正在尝试在xml中自定义一个不确定的进度条,但我找不到方法来对齐边缘.我从SDK资源中找到了默认的xml drawable,但它们只引用了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设置的不确定drawable有圆角.如果您需要方形(或可能是任何其他)边缘,则需要使用以下代码设置不确定的drawable:
// 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性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...