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

标签 android android-layout

我试图在 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/

相关文章:

Android View 拖放 - 仅当它与特定 View 位置匹配时才接受 View 拖放?

android - 广播接收器最高优先级不工作

android - 我是否需要具有 native 函数的单独库才能加载具有 main 函数的库?

java - 不读取文件

android - 删除 RecyclerView 项目之间的奇怪空间

android - 向数据库中插入数据时 logcat 出错

java - 如何在 Eclipse 中更改 Android 的 Java 构建路径?

android - 删除 actionbar item 蓝色背景

java - Android View 字段名称约定

android - 如何设置 edittext 未处于焦点时的 float 标签文本颜色与 edittext 提示颜色不同?