我期待我的进度条像这样工作:
无需更改界面设计。
我的布局如下:
显示进度条后,它变为:
你可以看到它已经将edittext和其他一些设计推到了下面。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".Login">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingTop="56dp"
android:paddingRight="24dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="24dp"
android:src="@drawable/cenviro" />
<com.rengwuxian.materialedittext.MaterialEditText
android:id="@+id/input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:hint="Email"
android:inputType="textEmailAddress"
app:met_floatingLabel="highlight" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="16dp"
android:visibility="gone"
android:id="@+id/relativeLayout">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:indeterminate="true"
android:indeterminateDrawable="@drawable/progress"
android:max="100"/>
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Logging in..."
android:textSize="20sp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/progressBar"/>
</RelativeLayout>
<com.rengwuxian.materialedittext.MaterialEditText
android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:hint="Password"
android:inputType="textPassword"
app:met_floatingLabel="highlight" />
如何在不改变界面的情况下显示进度条,就像我展示的第一张图片一样?
在登录按钮下添加此布局并从那里删除进度条布局。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:visibility="gone"
android:id="@+id/relativeLayout">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_centerInParent="true"
android:indeterminate="true"
android:indeterminateDrawable="@drawable/progress"
android:max="100"/>
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Logging in..."
android:textSize="20sp"
android:layout_centerInParent="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/progressBar"/>
</RelativeLayout>
从xml文件中删除进度条,然后在java文件中使用progressdialog
当任务开始时
private ProgressDialog dialog;
dialog = new ProgressDialog(activity);
dialog.setMessage("Doing something, please wait.");
dialog.show();
什么时候结束
if (dialog.isShowing()) {
dialog.dismiss();
}
首先,为什么您的布局父级是RelativeLayout,然后所有内容都在LinearLayout内?
然后,在LinearLayout中,两个视图不能自身重叠,因此您应该在LinearLayout之外设置ProgressBar RelativeLayout。
尝试以这种方式更改布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Login">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="16dp"
android:visibility="gone"
android:id="@+id/relativeLayout">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:indeterminate="true"
android:indeterminateDrawable="@drawable/progress"
android:max="100"/>
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Logging in..."
android:textSize="20sp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/progressBar"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingTop="56dp"
android:paddingRight="24dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="24dp"
android:src="@drawable/cenviro" />
<com.rengwuxian.materialedittext.MaterialEditText
android:id="@+id/input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:hint="Email"
android:inputType="textEmailAddress"
app:met_floatingLabel="highlight" />
<com.rengwuxian.materialedittext.MaterialEditText
android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:hint="Password"
android:inputType="textPassword"
app:met_floatingLabel="highlight" />
然后,您使用的是在LinearLayout内部没有效果的android:centerInParent = "true"
。
您正在使用电子邮件和密码中心的进度条,这就是进度条变为可见的原因然后pt在密码视图下方移动您的密码视图
您可以使用这样的默认进度条(根据您的例外图像)
ProgressDialog progressDialog = new ProgressDialog(activityCon);
progressDialog.setMessage("Logging In...");
progressDialog.setCancelable(false);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
隐藏if(progressDialog!= null)progressDialog.dismiss();
希望它能解决你的问题:-)