【问题标题】:ProgressBar setting custom drawable is filling the progressbarProgressBar设置自定义drawable正在填充进度条
【发布时间】:2016-05-04 08:55:20
【问题描述】:

我正在为我的水平progressBar 设置一个自定义progressbarDrawable,但它似乎填充了完整的progressbar,所以它总是设置为100%。

这是我的可绘制对象:

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

    <item
        android:id="@android:id/background"
        android:drawable="@drawable/gold_progress_bg" />
    <!--<item
        android:id="@android:id/secondaryProgress"
        android:drawable="@drawable/gold_progress_progress" />-->
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/gold_progress_progress" />

</layer-list>

这是我应用于视图的样式:

<style name="DottedVehicleProgressBar" parent="@android:style/Widget.Holo.Light.ProgressBar.Horizontal">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:indeterminateOnly">false</item>
        <item name="android:progress">50</item>
        <item name="android:progressDrawable">@drawable/dotted_progress_drawable</item>
    </style>

这里是 xml 中视图的定义:

<ProgressBar
        android:id="@+id/vehicle_dotted_progress"
        style="@style/DottedVehicleProgressBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:progress="50"
        app:tickInterval="10.0" />

【问题讨论】:

  • 这看起来像是搜索栏布局的可绘制进度。 ProgressBar 应该显示执行任务的整体进度。如果您想创建自己的自定义进度条,请查看this SO 答案。也适用于可绘制对象。
  • 您找到解决方案了吗?

标签: android android-xml android-drawable android-progressbar


【解决方案1】:

根据here 的回答,用&lt;clip&gt; 元素包围你的&lt;layer-list&gt; 将解决它。

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

        <item
            android:id="@android:id/background"
            android:drawable="@drawable/gold_progress_bg" />
        <!--<item
            android:id="@android:id/secondaryProgress"
            android:drawable="@drawable/gold_progress_progress" />-->
        <item
            android:id="@android:id/progress"
            android:drawable="@drawable/gold_progress_progress" />

    </layer-list>
</clip>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多