尽管滚动,如何使 ProgressBar 保持在屏幕中央 [英] How to make a ProgressBar stay in the center of screen despite scrolling
问题描述
我在 ScrollView 中有一个 ProgressBar,尽管用户向下或向上滚动,但我希望它保持垂直居中.但是,我不确定如何完成此操作.
I have a ProgressBar in a ScrollView, and I'd like it to stay centered vertically despite the user scrolling down or up. However, I'm not sure how to accomplish this.
这是我拥有的代码,虽然很简单.我有一个不确定的 ProgressBar:
Here's the code that I have, simple as it is. I have an indeterminate ProgressBar:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ocr_scroll_view"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<RelativeLayout android:id="@+id/image_holder"
android:layout_gravity="end"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ProgressBar android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:visibility="gone"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
我这样称呼它:
spinningProgressBar = (ProgressBar)findViewById(R.id.progressBar1);
spinningProgressBar.setIndeterminate(true);
spinningProgressBar.setVisibility(View.GONE);
在适当的时候设置其可见性.
Setting its visibility at the appropriate times.
非常感谢所有建议.
推荐答案
把它放在 ScrollView 之外.只需让 ScrollView 和 ProgressBar 重叠即可.
Put it outside of the ScrollView. Just have the ScrollView and the ProgressBar overlap.
您可以在此处阅读有关如何重叠视图的信息:Android 中的重叠视图
You can read about how to overlap views here: Overlapping Views in Android
有几种方法可以做到这一点,从 GridLayouts 到 RelativeLayouts,然后是编程方式.
There's a couple of ways to do it, ranging from GridLayouts to RelativeLayouts and then programatic ways to do it.
这篇关于尽管滚动,如何使 ProgressBar 保持在屏幕中央的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!