Android ProgressBar progress bar Progress at both ends are rounded corners of the method

Source: Internet
Author: User

Transfer from HTTP://WWW.JIANSHU.COM/P/6E7EA842D5CE

In addition, the working principle can refer to http://blog.csdn.net/lan603168/article/details/44705425

ProgressBar may encounter a problem when customizing, I hope the progress in the progress bar is rounded at both ends (or the end of the progress is rounded);
Such as:


progress bar Rounder

But according to the custom shape or the layer-list is always difficult to do, almost all of the clip into a right angle;


Progress bar

;

The reason for the problem is that the following links will also have similar answers:
What do I need to have rounded corners on both sides of Android development progress?

Why is it right-angled? The reason for this is that clip is cut, so we're not enough to clip and use the scale tag. The answer to the above link is to define a. 9 picture can meet the requirements, because we are here is a solid color progress, so there is no need to make a. 9 of the picture, and only need to use the same method to refer to our definition of a shape on it;
See Code:

<ProgressBar    android:layout_below="@id/text_1"    android:layout_marginTop="16dp"    android:layout_width="match_parent"    android:layout_height="wrap_content" android:id="@+id/progressbar_1" style="?android:attr/progressBarStyleHorizontal" android:max="100" android:progress="40" android:progressDrawable="@drawable/progress_bar_drawable" />

Progressdrawable referenced by progress_bar_drawable:

<?xml version= "1.0" encoding= "Utf-8"?><Layer-listXmlns:android="Http://schemas.android.com/apk/res/android" ><ItemAndroid:id="@android: Id/background" ><Shape><Cornersandroid:toprightradius="20DP"android:bottomrightradius="20DP"/><SolidAndroid:color="#ED30353E"/></Shape></Item><ItemAndroid:id="@android: Id/secondaryprogress" ><ScaleAndroid:scalewidth="100%" ><Shape><Cornersandroid:toprightradius="20DP"android:bottomrightradius="20DP"/><SolidAndroid:color="#11ce33"/></Shape></scale> </ item> <item android:id= "@android: Id/progress" > <!--<clip> <shape> <corners android:toprightradius= "20DP" Android: bottomrightradius= "20DP"/> <solid android:color= "#FF009898"/> </shape> </clip>-<scale android:scalewidth= "100%" android:drawable= "@drawable/progress_ Bar_ct "/> </item></LAYER-LIST>            

Here's the point:

<scale android:scaleWidth="100%"            android:drawable="@drawable/progress_bar_ct" />

We have specified a custom shape:progress_bar_ct.xml

<?xml version= "1.0" encoding= "Utf-8"?><Shapexmlns:android= "http://schemas.android.com/apk/res/ Android "android:shape=" rectangle "> <!--solid Specifies the fill color of the shape, only android:color one property--<solid android:color= "#FF009898"/> <!--padding set the content area away from the boundary--<!--Corners set the fillet, Only for rectangle---<corners  Android:bottomrightradius= "20DP" android:toprightradius=< Span class= "Hljs-value" > "20DP"/> </SHAPE>    

This makes it unnecessary to customize the picture of. 9.
PS: Because my demand is the right side is rounded corner, if you need 4 corners are rounded corner only need to modify a bit of code;

<corners android:bottomRightRadius="20dp"        android:topRightRadius="20dp"/>

Modified to:

<corners android:radius="20dp" />

To



Wen/heybik (author of Jane's book)
Original link: http://www.jianshu.com/p/6e7ea842d5ce
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

Android ProgressBar progress bar Progress at both ends are rounded corners of the method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.