Android 按钮中间的进度条
我想在标准按钮的中间创建一个进度条,如下所示: 在xml布局中,当我单击progressbar时,我确实看到它位于我希望它位于的位置,但在实时上,我看不到它,它感觉像是隐藏在按钮下面。 我试过:Android 按钮中间的进度条,android,android-layout,android-xml,android-button,android-progressbar,Android,Android Layout,Android Xml,Android Button,Android Progressbar,我想在标准按钮的中间创建一个进度条,如下所示: 在xml布局中,当我单击progressbar时,我确实看到它位于我希望它位于的位置,但在实时上,我看不到它,它感觉像是隐藏在按钮下面。 我试过: 更改视图的位置(进度条上方/下方的按钮) 不确定 玩ProgressBar的风格 似乎什么也没起作用 以下是我的xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://sch
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<Button
android:id="@+id/button_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:elevation="1dp"
android:text="test button" />
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button_id"
android:layout_alignTop="@+id/button_id"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:indeterminateTint="@android:color/holo_blue_dark"
android:visibility="visible" />
</RelativeLayout>
在预览中,进度条始终不可见(至少对我而言) 问题是,您对按钮应用了标高。这将更改视图的z级别。因此ProgressBar实际上位于按钮后面,因为ProgressBar没有高程 将ProgressBar的高程设置为3dp对我来说很有效
编辑:
你会更好的,使用一个
该问题与
高程相关。将高程添加到进度条中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<Button
android:id="@+id/button_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:elevation="1dp"
android:text="test button" />
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button_id"
android:layout_alignTop="@+id/button_id"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:elevation="2dp"
android:indeterminateTint="@android:color/holo_blue_dark"
android:visibility="visible" />
</RelativeLayout>
如果您仍然需要支持21岁以上的设备(因此无法使用android:elevation
),请尝试将按钮包装到另一个虚拟布局中。我以FrameLayout
为例
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
</FrameLayout>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="24dp"
android:layout_gravity="center"
android:indeterminateTint="@android:color/white" />
</FrameLayout>
可能是因为您需要更改进度的颜色,而不是以前使用不同的颜色。请将这些颜色添加到主题库样式#ffff4444#ff0099cc中,然后再试一次,只是一条用户意见:看起来很糟糕。至少要隐藏文本。@m0skit0显然。。。这只是一个例子,在一些随机绘制程序上制作。忘了吧。只需将提升添加到progressbar就可以了。甚至认为提升仅来自api 21。为什么会出现提升问题?解决这个问题。谢谢,如果我只能在xml中优雅地使用progressdialog,而不需要任何代码,那么我为什么要使用progressdialog呢?因为我觉得它不太“优雅”。将ProgressBar设置为可见/不可见并不比显示ProgressDialog.ProgressDialog id少多少代码。ProgressDialog id已被api 26弃用,建议使用ProgressBar
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
</FrameLayout>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="24dp"
android:layout_gravity="center"
android:indeterminateTint="@android:color/white" />
</FrameLayout>