【问题标题】:custom progress drawable not showing sometimes自定义进度可绘制有时不显示
【发布时间】:2012-10-18 16:02:46
【问题描述】:

我有一个非常奇怪的问题 - 我为进度条定义了一个可绘制的自定义进度

有时显示有时不显示。

我尝试清理我的项目,重新启动 eclipse,甚至重新启动计算机。

它仍然会发生。

这里是进度可绘制的 xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@android:id/background">
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners android:radius="5dp" />
    <gradient
        android:startColor="#6f7754"
        android:endColor="#858762"
        android:angle="90"/>
</shape>
</item>

<item android:id="@android:id/secondaryProgress">
<clip>
    <shape 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">

        <corners android:radius="5dp" />
        <gradient
                android:startColor="#ffba00"
                android:endColor="#af6c03"
                android:angle="90"/>
    </shape>
</clip>
</item>

<item android:id="@android:id/progress">
<clip>
    <shape 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">

        <corners
            android:radius="5dp" />
        <gradient
            android:startColor="#ffba00"
            android:endColor="#af6c03"
            android:angle="90" />
    </shape>
</clip>

这是我使用它的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginBottom="2dp"
android:background="@drawable/quick_action_item_btn">

<ImageView
    android:id="@+id/icon" 
    android:layout_width="21dp" 
    android:layout_height="21dp"
    android:scaleType="centerInside"/>

<ProgressBar 
    android:id="@+id/progress"
    android:layout_width="20dp"
    android:layout_height="4dp"
    android:layout_marginTop="2dp"
    style="@android:style/Widget.ProgressBar.Horizontal"
    android:progressDrawable="@drawable/achievement_progress_bar"/>

</LinearLayout>

【问题讨论】:

    标签: android progress-bar


    【解决方案1】:

    试试这个

    android:indeterminateDrawable="@drawable/yourXML"
    

    它对我有用..

    【讨论】:

    • 在 android:progressDrawable="@drawable/achievement_progress_bar" 之外添加它?还是取而代之?
    【解决方案2】:

    它对我来说工作正常。只需将您的 indeterminateDrawable 设置为您的自定义 xml 文件。应该没问题..

    【讨论】:

      【解决方案3】:

      也许这与这个问题类似...SharedPreferences.onSharedPreferenceChangeListener not being called consistently

      自定义 xml 是否定义为活动的变量?如果没有,可能它正在被垃圾收集器收集。我的建议是让它成为类(活动类)的字段变量。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-23
        • 1970-01-01
        • 2017-08-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多