尽管滚动,如何使 ProgressBar 保持在屏幕中央

mik*_*ell 2 android vertical-alignment

我在 ScrollView 中有一个 ProgressBar,尽管用户向下或向上滚动,但我希望它保持垂直居中。但是,我不确定如何实现这一点。

这是我拥有的代码,虽然很简单。我有一个不确定的 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" />
Run Code Online (Sandbox Code Playgroud)

我这样称呼它:

    spinningProgressBar = (ProgressBar)findViewById(R.id.progressBar1);
    spinningProgressBar.setIndeterminate(true);
    spinningProgressBar.setVisibility(View.GONE);
Run Code Online (Sandbox Code Playgroud)

在适当的时间设置其可见性。

非常感谢所有建议。

Ale*_*x K 7

把它放在 ScrollView 之外。只需让 ScrollView 和 ProgressBar 重叠即可。

您可以在此处阅读有关如何重叠视图的信息:Android 中的重叠视图

有几种方法可以做到这一点,从 GridLayouts 到 RelativeLayouts,然后是编程方式来做到这一点。


Boo*_*ger 7

您需要 ScrollView 与布局中的 ProgressDialog 处于同一级别。

这是概念上的:

<RelativeLayout>
    <ProgressDialog>      
    <ScrollView>      
<RelativeLayout>
Run Code Online (Sandbox Code Playgroud)