圆形进度条未覆盖整个可用 space
Circular progress bar not covering whole available space
我已经坚持了一段时间。 #newbieAndroidDeveloper
我正在制作一个圆形进度条。问题是动画圈没有利用可用的进度条space。
屏幕截图应该可以解释问题。
蓝色不完整的圆圈是圆形进度条。黄色方块是进度条的背景。红色箭头未使用space,这是值得关注的问题。
进度条和背景的大小通过代码设置。
我想让循环进度条使用整个space.
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>
其实这个activity里面还有其他元素。我删除了它们以专注于这个问题。
非常感谢任何帮助。
尽管我没有找到为什么不使用未使用的 space 的答案,但我发现了另一个很酷的进度条库。 ProgressWheel.
它真的是可定制的。您可以独立于背景单独调整进度圈的大小,这是默认的 android 进度条工具无法做到的。这解决了我的问题。
希望对大家有所帮助。但是我还是很好奇为什么 android 的默认进度条没有用完问题中提到的整个 space 。再次欢迎任何帮助。
我已经坚持了一段时间。 #newbieAndroidDeveloper
我正在制作一个圆形进度条。问题是动画圈没有利用可用的进度条space。
屏幕截图应该可以解释问题。
蓝色不完整的圆圈是圆形进度条。黄色方块是进度条的背景。红色箭头未使用space,这是值得关注的问题。
进度条和背景的大小通过代码设置。 我想让循环进度条使用整个space.
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>
其实这个activity里面还有其他元素。我删除了它们以专注于这个问题。 非常感谢任何帮助。
尽管我没有找到为什么不使用未使用的 space 的答案,但我发现了另一个很酷的进度条库。 ProgressWheel.
它真的是可定制的。您可以独立于背景单独调整进度圈的大小,这是默认的 android 进度条工具无法做到的。这解决了我的问题。
希望对大家有所帮助。但是我还是很好奇为什么 android 的默认进度条没有用完问题中提到的整个 space 。再次欢迎任何帮助。