2017-06-02 47 views
-6

自定义视图我创建一个视图如下设计在这里如何创建的Android

enter image description here

请建议的方法来创建这种类型的自定义视图。

+0

您是否想要制作圆形进度条? –

+0

可能[这](https://stackoverflow.com/questions/14688117/how-to-make-circle-custom-progress-bar-in-android)一个帮助你的兄弟.. –

+0

'请建议的方式来创建此类型的自定义视图。“我可以建议你谷歌的一些教程,而不是在这里要求教程。 –

回答

1

您需要创建两个文件,绘制此

创建资源这两个文件>绘制

1 circle_shape.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="ring" 
    android:innerRadiusRatio="2.8" 
    android:thickness="10dp" 
    android:useLevel="false"> 
    <solid android:color="#CCC" /> 

</shape> 

2. circular_progress_bar.xml

<?xml version="1.0" encoding="utf-8"?> 
<rotate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromDegrees="270" 
    android:toDegrees="270"> 
    <shape 
     android:innerRadiusRatio="2.8" 
     android:shape="ring" 
     android:thickness="10dp" 
     android:useLevel="true"><!-- this line fixes the issue for lollipop api 21 --> 

     <gradient 
      android:angle="0" 
      android:endColor="#e2d631" 
      android:startColor="#dcdc38" 
      android:type="sweep" 
      android:useLevel="false" /> 
    </shape> 
</rotate> 

现在在您的layout.xml中,即res> layout>(您的布局文件)

    <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        > 

        <ProgressBar 
         android:id="@+id/pb_syllabus" 
         style="?android:attr/progressBarStyleHorizontal" 
         android:layout_width="120dp" 
         android:layout_height="120dp" 
         android:layout_centerInParent="true" 
         android:background="@drawable/circle_shape" 
         android:progress="60" 
         android:progressDrawable="@drawable/circular_progress_bar" /> 

        <TextView 
         android:layout_width="40dp" 
         android:layout_height="wrap_content" 
         android:layout_centerInParent="true" 
         android:gravity="center" 
         android:text="60%" 
         android:textColor="#ffffff" 
         android:textSize="21sp" 
         android:textStyle="bold" /> 
       </RelativeLayout> 
+0

谢谢你,兄弟,它帮助了我。 –

+0

如果此答案有效,请将其标记为“完成” –