与Android的填充进度条 [英] Android progress bar with padding

查看:111
本文介绍了与Android的填充进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让我的进度条看起来就像这样:

I want to make my progress bar looks something like that:

我不想使用图片,所以我试图用形状做出这样的:

I dont want to use images, so I have tried to make this with the shapes:

<item android:id="@android:id/background">
    <shape>
        <corners android:radius="50dp" />

        <gradient
            android:angle="270"
            android:centerColor="#2a2723"
            android:centerY="0.75"
            android:endColor="#2a2723"
            android:startColor="#2a2723" />
    </shape>
</item>
<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <corners android:radius="50dp" />

            <gradient
                android:angle="270"
                android:centerColor="#16e61c"
                android:centerY="0.75"
                android:endColor="#9dfd6e"
                android:startColor="#16e61c" />
        </shape>
    </clip>
</item>
<item android:id="@android:id/progress">
    <clip>
        <shape>
            <corners android:radius="50dp" />

            <gradient
                android:angle="270"
                android:endColor="#9dfd6e"
                android:startColor="#16e61c" />
        </shape>
    </clip>
</item>

但我不能设置填充为绿线(IVE试图处处设置它的地方是可能的),而我也无法做出这样的圆角(看起来像角落安卓半径不工作)。请帮我

But I cant set padding for the green line (Ive tried to set its everywhere where it was possible), and also I can't make such round corners (looks like corners android:radius isn't working). Please help me

推荐答案

一个简单的解决方法是换进度条到布局已经圆润的造型和相同的背景色进度条。

A simple workaround is to wrap progress bar into layout which has rounded shape and same background color as progress bar.

样品进度条绘制(绘制/ progress_bar.xml):

Sample progress bar drawable (drawable/progress_bar.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>
            <corners android:radius="50dip" />
            <solid android:color="@color/white"/>
            <padding android:bottom="3dip" android:left="3dip" android:right="3dip" android:top="3dip" />
        </shape>
    </item>

    <item android:id="@android:id/progress">
        <bitmap android:src="@drawable/test_progress_bar_progress" android:tileMode="repeat"/>
    </item>
</layer-list>

进度条风格:

Progress bar style:

<resources>
    <style name="ProgressBarStyle" parent="@android:style/Widget.ProgressBar.Horizontal">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">10dip</item>
        <item name="android:max">100</item>
        <item name="android:progressDrawable">@drawable/progress_bar</item>
    </style>
</resources>

布局形状(绘制/ rounded_shape.xml):

Layout shape (drawable/rounded_shape.xml):

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <padding android:top="2dip" android:left="2dip" android:right="2dip" android:bottom="2dip"/>
    <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
    <solid android:color="@color/white"/>
</shape>

活动的布局:

Activity layout:

<!-- ... -->
      <LinearLayout                     
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:background="@drawable/rounded_shape"
                  android:layout_marginLeft="30dip"
                  android:layout_marginRight="30dip">
            <ProgressBar
                    android:id="@+id/testSummaryProgressBar"
                    android:progress="10"
                    style="@style/ProgressBarStyle"/>
        </LinearLayout>
<!-- ... -->

功效:

要增加的进度条填充,你必须增加填充在rounded_shape文件。

To increase padding of progress bar you have to increase padding in rounded_shape file.

这篇关于与Android的填充进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆