2017-06-13 9 views
-1

内側のグローがある円形のプログレスバーを作成したいと思いますが、グラデーションの開始、中央、終了の色でプログレスdrawableと動作させるようです。巡回プログレスバーのグラデーション

This is what i want to create

This is what i could create

私は私の現在のアプローチを共有します。

background.xml

<shape 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="ring" 
android:innerRadiusRatio="2.5" 
android:thickness="10dp" 
android:useLevel="false"> 

<gradient 

    android:startColor="#b6b6b6" 
    android:centerColor="#eeeeee" 
    android:endColor="#b6b6b6" 
/> 
</shape> 

progress.xml

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

    <gradient 
     android:angle="0" 
     android:startColor="#082a55" 
     android:centerColor="#0a3973" 
     android:endColor="#082a55" 

     android:useLevel="false" /> 
</shape> 
</rotate> 

mainactivity.xml

<ProgressBar 
    android:id="@+id/progressBar" 
    android:layout_width="200dp" 
    android:layout_height="200dp" 
    android:indeterminate="false" 
    android:layout_centerInParent="true" 
    android:progressDrawable="@drawable/circular_progress_bar" 
    android:background="@drawable/cicle_shape" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:max="100" 
    android:progress="20" /> 
+0

私のANSをチェックして、私が必要と背景がまだソリッドカラーである、それはグラデーション効果を生成しない、任意のクエリの場合は返信用 –

答えて

0

が、これはプロの作成

1ステップに従いますあなたの活動ファイル内drawblwフォルダ内のgressbar.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 
     android:innerRadiusRatio="3" 
     android:shape="ring" 
     android:thicknessRatio="10.0" 
     android:useLevel="false"> 
     <solid android:color="@color/colorWhite" /> 
     <stroke android:color="@color/colorPrimary" /> 
    </shape> 
</item> 
<item android:id="@android:id/progress"> 
    <rotate 
     android:fromDegrees="270" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:toDegrees="270"> 
     <shape 
      android:innerRadiusRatio="3" 
      android:shape="ring" 
      android:thicknessRatio="10.0" 
      android:useLevel="true"> 
      <solid android:color="@color/colorAccent" /> 
     </shape> 
    </rotate> 
</item> 

</layer-list> 

2.今、この

<ProgressBar 
      android:id="@+id/circularProgressBar" 
      style="?android:attr/progressBarStyleHorizontal" 
      android:layout_width="40dip" 
      android:layout_height="40dip" 
      android:layout_centerInParent="true" 
      android:layout_marginLeft="5dp" 
      android:layout_toRightOf="@+id/txt_continue" 
      android:indeterminate="false" 
      android:padding="2dp" 
      android:progressDrawable="@drawable/progressbar" /> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@id/circularProgressBar" 
      android:layout_alignLeft="@id/circularProgressBar" 
      android:layout_alignRight="@id/circularProgressBar" 
      android:layout_alignTop="@id/circularProgressBar" 
      android:gravity="center" 
      android:text="30" 
      android:textSize="16sp" /> 

2.のようなあなたのレイアウトファイルでこれを追加し

_progressBar = (ProgressBar) findViewById(R.id.circularProgressBar); 
    _progressBar.setProgress(0); 
    _progressBar.setMax(K); 
    txtTime = (TextView) findViewById(R.id.textView1); 
    final Calendar calendar = Calendar.getInstance(); 

    long cur = calendar.getTimeInMillis(); 
    long goal = (cur + (30 * 1000)); 

    doSomethingRepeatedly(goal); 

4.このような方法の一つを作りなさい

private void doSomethingRepeatedly(final long goal) { 

    timer = new Timer(); 
    timer.scheduleAtFixedRate(new TimerTask() { 
     public void run() { 

      try { 
       final Calendar calendar = Calendar.getInstance(); 

       if (goal > calendar.getTimeInMillis()) { 
        Log.e("CHK", "CAlled"); 
        runOnUiThread(new Runnable() { 
         @Override 
         public void run() { 

          Log.d("Time Plus", "Time Plus" + K--); 
          _progressBar.setProgress(K); 
          txtTime.setText(String.valueOf(K)); 
         } 
        }); 
       } else { 
        runOnUiThread(new Runnable() { 
         @Override 
         public void run() { 

          //Log.d("Time Plus", "Time Plus" + K--); 
          _progressBar.setProgress(K); 
          txtTime.setText(String.valueOf(K)); 
          btnNotnow.setVisibility(View.VISIBLE); 
          txtContinue.setVisibility(View.GONE); 
          _progressBar.setVisibility(View.GONE); 
          txtTime.setVisibility(View.GONE); 
         } 
        }); 
        Log.e("CHK", "Reached Limit"); 
        cancel(); 
       } 

       //Your code 

      } catch (Exception e) { 
       runOnUiThread(new Runnable() { 
        @Override 
        public void run() { 
         // Do some stuff 
         //ivGIF.setVisibility(View.INVISIBLE); 
         //Log.d("Time Plus", "Time Plus" + K++); 
        } 
       }); 

       Log.e("CHK", "Exception"); 
       // TODO: handle exception 
      } 
     } 
    }, 0, 1000); 
} 
+0

感謝を私に尋ねます。 – user2955425

+0

@ user2955425私の更新されたansを確認してください –

+0

私は進行状況が完了するとグラデーションが欲しくありません。私が望むものをよりよく理解するために、私の望む添付画像を見てください。 – user2955425