如何在屏幕中央设置android进度条

Cha*_*ndu 13 layout android progress-bar

我试图在屏幕中央显示进度条,但它不会显示在中心.下面是我的布局.我在这做错了什么?基本上这是一个布局,以显示图像和Android画廊小部件在上面.当用户点击缩略图时,我正在从网络加载图像,我想在加载图像时显示进度对话框.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/container" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical">

    <Gallery android:id="@+id/gallery" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:gravity="top" />

    <ImageView android:id="@+id/actualimage" android:scaleType="fitCenter"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:visibility="gone" android:layout_gravity="center_vertical|center_horizontal|center"
        android:adjustViewBounds="true" />

    <ProgressBar android:id="@+android:id/progress_small1"
        android:layout_height="wrap_content" android:layout_width="wrap_content"
        android:visibility="visible" android:layout_gravity="center_vertical|center_horizontal"
        android:gravity="center_vertical|center_horizontal" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Pau*_*rke 41

使用LinearLayout将垂直堆叠视图.现在,你的ImageViewProgressBar正在争取的中心位置.对于这种情况,我肯定会推荐一个RelativeLayout.

RelativeLayout,你用android:layout_centerInParent="true".

  • 相对布局为我做了伎俩.非常感谢 (2认同)

500*_*865 5

android:gravity="center"在根上LinearLayout。当您android:visibility想要显示ProgressBargoneProgressBar