search

Home  >  Q&A  >  body text

Android开发中Progress需要两边都是圆角怎么办?

这里的两边都是圆角,指的是progressbar的progress部分
比如,需要这个效果:

如果使用shape,progress的右边是直角,所以使用了.9图
但是实际中,设置progress为10了之后(max为100),整体还是很宽,感觉像是progress属性不能用了

原始界面文件中的使用:

<ProgressBar
        android:id="@+id/live_channel_progres"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="112dp"
        android:layout_height="15dp"
        android:max="100"
        android:progress="10"
        android:progressDrawable="@drawable/progress_bg" />

progress的drawable:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
 
    <!-- 背景  gradient是渐变,corners定义的是圆角 -->
    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="30dp" />
 
            <solid android:color="#ff0" />
        </shape>
    </item>
    <!-- 进度条 -->
    <item android:id="@android:id/progress" android:drawable="@drawable/live_channel_progress"/>
    
 
</layer-list>
怪我咯怪我咯2810 days ago953

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 15:08:28

    Solved. My question may not be clear, causing someone to misunderstand it. The current requirements are:

    The progress part of progress needs to have rounded corners on both sides

    I tried using shape from the beginning, but it didn’t work
    I copied the answer on the first floor and tried it, and the effect was the same as my initial result

    If you use the .9 picture, you can avoid this problem, just put the question:

    <!-- 进度条 -->
        <item android:id="@android:id/progress" android:drawable="@drawable/live_channel_progress"/>

    Just change this part:

    <!-- 进度条 -->
        <item android:id="@android:id/progress">
             <scale android:scaleWidth="100%"
                   android:drawable="@drawable/live_channel_progress" />
        </item>

    This is because the Progressbar will clip when drawing. If you specify the clip attribute, the right side will definitely be cut into a right angle, so you need to use scale in the item. It will be perfect with the .9 picture.

    http://stackoverflow.com/questions/2078809/progress-bar-rounded-on-both-sides-in-android

    reply
    0
  • 迷茫

    迷茫2017-04-17 15:08:28

       <ProgressBar
              android:id="@+id/progressBar"
              android:layout_width="160dp"
              android:layout_height="7dp"
              style="@style/ProgressBar_Validity"
          />

    style:

       <style name="ProgressBar_Validity" parent="@android:style/Widget.ProgressBar.Horizontal">
            <item name="android:indeterminateOnly">false</item>
            <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
            <item name="android:progressDrawable">@drawable/progress_validity</item>
        </style>

    progress_validity:

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <item android:id="@android:id/secondaryProgress">
    
            <clip >
                <shape >
                    <corners android:radius="6dip" />
                    <solid android:color="#EAEAEA"/>
                </shape>
            </clip>
        </item>
    
        <item android:id="@android:id/progress">
            <clip >
                <shape >
                    <corners android:radius="6dip" />
                    <solid android:color="#03A9F4"/>
                </shape>
    
            </clip>
        </item>
    </layer-list> 

    There is a problem with the formatting. Please sort it out yourself. . Correct by personal test.

    reply
    0
  • Cancelreply