【发布时间】:2016-08-01 13:30:47
【问题描述】:
我被这个问题困扰了一段时间。可能有人可以提供帮助。
问题是我的android圆形进度条的背景根据手机屏幕大小有不同的大小。
屏幕截图应该可以解释问题。
蓝色不完整的圆圈是圆形进度条(动画)。它实际上应该在白色圆圈的顶部运行。它仅适用于特定的屏幕尺寸。
白色圆圈设置为进度条的背景drawable。
这里是代码。 (我只放了需要的代码)
acivity_countdown.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="#FD4C0D"
>
<FrameLayout
android:id="@+id/CountDownProress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FD4C0D"
>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:indeterminate="false"
android:progressDrawable="@drawable/circular_progress_bar"
android:layout_alignParentBottom="true"
android:background="@drawable/circular_shape"
android:layout_centerHorizontal="true"
android:max="500"
android:progress="0"
></ProgressBar>
<LinearLayout.../><!--this layout contains text inside circular progress -->
</FrameLayout>
<FrameLayout.../><!--this layout contains button under circular progress -->
</LinearLayout>
circular_progress_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="0">
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thickness="3dp"
android:useLevel="true">
<gradient
android:angle="0"
android:endColor="#005B7F"
android:startColor="#005B7F"
android:type="sweep"
android:useLevel="false">
</gradient>
</shape>
</rotate>
circular_shape.xml(背景可绘制)
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:useLevel="false"
android:innerRadius="145dp"
android:shape="ring"
android:thickness="0.8dp"
>
<solid android:color = "#ffffff"/>
</shape>
我尝试根据https://stackoverflow.com/a/9362168/3929188 使圆形形状.xml(进度条的背景)根据屏幕大小缩放。但是从drawable创建位图xml对我来说是一个挑战,我根本做不到(noobie developer)。
我尝试为 circular_progress_bar.xml 设置背景,使蓝色圆圈动画在白色圆圈之上,但失败了。
欢迎任何想法!
【问题讨论】:
标签: android xml layout progress-bar drawable