gpt4 book ai didi

android - ProgressDialog 旋转圈

转载 作者:IT王子 更新时间:2023-10-28 23:39:40 26 4
gpt4 key购买 nike

我想像这样实现 ProgressDialog,不需要额外的框架。: Pic

但我得到了这个。我怎么能改变呢?

enter image description here

这是我的 ProgressDialog 代码。提前致谢

private ProgressDialog mProgressDialog;
............
mProgressDialog = new ProgressDialog(activity);
mProgressDialog.setIndeterminate(false);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
............
public class ProgressTask extends AsyncTask <Fragment,Void,Fragment>{
@Override
protected void onPreExecute(){
mProgressDialog.show();
}

@Override
protected Fragment doInBackground(Fragment... arg0) {
//my stuff is here
}

@Override
protected void onPostExecute(Fragment result) {
mProgressDialog.dismiss();
}
}

最佳答案

只需将布局中的 ProgressDialog 更改为 ProgressBar:

res/layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
//Your content here
</LinearLayout>

<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone"
android:indeterminateDrawable="@drawable/progress" >
</ProgressBar>
</RelativeLayout>

src/yourPackage/YourActivity.java

public class YourActivity extends Activity{

private ProgressBar bar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
bar = (ProgressBar) this.findViewById(R.id.progressBar);
new ProgressTask().execute();
}
private class ProgressTask extends AsyncTask <Void,Void,Void>{
@Override
protected void onPreExecute(){
bar.setVisibility(View.VISIBLE);
}

@Override
protected Void doInBackground(Void... arg0) {
//my stuff is here
}

@Override
protected void onPostExecute(Void result) {
bar.setVisibility(View.GONE);
}
}
}

drawable/progress.xml 这是我用来更改默认颜色的自定义 ProgressBar

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

<!--
Duration = 1 means that one rotation will be done in 1 second. leave it.
If you want to speed up the rotation, increase duration value.
in example 1080 shows three times faster revolution.
make the value multiply of 360, or the ring animates clunky
-->
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1"
android:toDegrees="360" >

<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false" >
<size
android:height="48dip"
android:width="48dip" />

<gradient
android:centerColor="@color/color_preloader_center"
android:centerY="0.50"
android:endColor="@color/color_preloader_end"
android:startColor="@color/color_preloader_start"
android:type="sweep"
android:useLevel="false" />
</shape>

</rotate>

关于android - ProgressDialog 旋转圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15585749/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com