我希望进度条的工作方式如下:
无需更改界面设计。
我的布局就像:
显示进度条后,它变为:
如您所见,它已将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" />
如何在不改变界面的情况下显示进度条,就像我显示的第一张照片一样?
答案 0 :(得分:1)
在登录按钮下方添加此布局,并从此处删除进度栏布局。
<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>
答案 1 :(得分:0)
从xml文件中删除进度栏,然后在
之类的Java文件中使用 progressdialog任务开始时
private ProgressDialog dialog;
dialog = new ProgressDialog(activity);
dialog.setMessage("Doing something, please wait.");
dialog.show();
结束时间
if (dialog.isShowing()) {
dialog.dismiss();
}
答案 2 :(得分:0)
首先,为什么您的布局父级是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" />
然后,您使用的android:centerInParent = "true"
在LinearLayout内部无效。