我在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" />
我这样称呼它:
spinningProgressBar = (ProgressBar)findViewById(R.id.progressBar1);
spinningProgressBar.setIndeterminate(true);
spinningProgressBar.setVisibility(View.GONE);
在适当的时间设置其可见性。
非常感谢所有建议。
将其放在ScrollView的外部。只需使ScrollView和ProgressBar重叠即可。
您可以在此处阅读有关如何重叠视图的信息:Overlapping Views in Android
有多种方法可以做到,从GridLayouts到RelativeLayouts,然后是编程的方法。
您需要ScrollView与Layout中的ProgressDialog处于同一级别。
这里是概念:
<RelativeLayout>
<ProgressDialog>
<ScrollView>
<RelativeLayout>
您可以将其插入到scrollview标签中
android:fillViewport="true"