Ben*_*aye 6 android android-layout
我正在尝试在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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
但它并没有改变形状.我发布了图片,但我还没有足够的声誉.我错过了什么?谢谢你的帮助.
小智 12
我只是有同样的问题,似乎使用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));
Run Code Online (Sandbox Code Playgroud)
然后是我使用的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>
Run Code Online (Sandbox Code Playgroud)
我需要重复图像,所以我创建了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>`
Run Code Online (Sandbox Code Playgroud)
drawable/progress_1是真实图像,我想重复作为不确定进度条的背景.
这个解决方案对我有用.
这对我有用.没有PNG.只是颜色.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="0dip" />
<stroke android:width="2px" android:color="#80c4c4c4"/>
<solid android:color="#08000000"/>
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="0dip" />
<solid android:color="#11416a"/>
</shape>
</clip>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
5144 次 |
| 最近记录: |