2016-08-16 8 views
1

これではしばらく時間がかかりました。 #newbieAndroidDeveloper利用可能なスペース全体をカバーしていない円の進捗バー

私は円形の進行状況バーを作成しています。問題はアニメーションサークルがプログレスバーの利用可能なスペースを利用していないことです。

スクリーンショットで問題を説明する必要があります。

enter image description here

青色不完全な円は、円形のプログレスバーです。黄色い四角は進行状況バーの背景です。赤い矢印は問題のある未使用スペースです。

プログレスバーと背景のサイズはコードで設定します。 私は円形の進行状況バーを全体のスペースで使いたいと思っています。

RaceLiveActivity.java

public class RaceLiveActivity extends AppCompatActivity { 
    Drawable drawable; 
    String length; 
    int len, totalDistance; 
    TextView textViewDistance, textViewTime, textViewSpeed; 
    FrameLayout raceFrame; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     totalDistance = 0; 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_race_live); 

     //TO FIND WIDTH AND HEIGHT OF PHONE SCREEN 
     DisplayMetrics displaymetrics = new DisplayMetrics(); 
     getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); 

     //SET WIDTH AND HEIGHT 
     raceLiveActivity = this; 

     ProgressBar prog=(ProgressBar) findViewById(R.id.progressBar1); 
     FrameLayout.LayoutParams FrameLP1 = new FrameLayout.LayoutParams(displaymetrics.widthPixels-100 , displaymetrics.widthPixels -100); 
     FrameLP1.gravity = Gravity.CENTER; 
     prog.setBackgroundColor(Color.YELLOW); 
     prog.setLayoutParams(FrameLP1); 


     length = "1";//int1.getStringExtra("length"); 
     len = Integer.valueOf(length); 
     ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar1); 
     ObjectAnimator animation = ObjectAnimator.ofInt (progressBar, "progress", 0, 500); // see this max value coming back here, we animale towards that value 
     animation.setDuration (len * 60000); //in milliseconds 
     animation.setInterpolator (new DecelerateInterpolator()); 
     animation.start(); 
    } 
} 

activity_race_live.xml

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/BackLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="#FD4C0D"> 
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/RaceProress" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="3" 
     android:background="#FD4C0D" 
     > 
     <ProgressBar 
      android:id="@+id/progressBar1" 
      style="?android:attr/progressBarStyleHorizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:indeterminate="false" 
      android:progressDrawable="@drawable/circular_progress_bar" 
      android:progress="0" 
      ></ProgressBar> 

    </FrameLayout> 
</LinearLayout> 

circular_progress_bar.xml(描画可能形状)

<?xml version="1.0" encoding="utf-8"?> 
<rotate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromDegrees="0" 
    android:toDegrees="0"> 
    <shape 
     android:shape="ring" 
     android:thickness="3dp" 
     android:useLevel="true"> 
     <gradient 
      android:angle="0" 
      android:endColor="#005B7F" 
      android:startColor="#005B7F" 
      android:type="sweep" 
      android:useLevel="false"> 
     </gradient> 
    </shape> 
</rotate> 

実際にこのアクティビティには他の要素があります。私は問題に集中するためにそれらを削除しました。 何か助けていただければ幸いです。

+0

android:layout_margin = "0dp" アンドロイド:パディング= "0dp" – X3Btel

+0

いいえ、それは役に立たなかった。それを加えた後のUIの変更はありません。 –

答えて

1

なぜ私は未使用のスペースを使用していないのか答えを見つけられませんでしたが、クールな別のクールなプログレスバーライブラリが見つかりました。 ProgressWheel.

本当にカスタマイズ可能です。アンドロイドのデフォルトのプログレスバーツールではできないバックグラウンドとは独立して、プログレスサークルのサイズだけを調整することができます。これは私の問題を解決します。

enter image description here

は、それが誰かに役立ちます願っています。しかし、私はまだ興味がありますなぜアンドロイドのデフォルトの進行状況バーは、質問に記載されているように全体のスペースを使用していないです。どんな援助も再び歓迎されます。

関連する問題