显示屏幕进度条中心 [英] show progress bar center of screen

查看:55
本文介绍了显示屏幕进度条中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在布局内使用进度条.当我启动应用程序时,进度条总是与屏幕的左上角对齐.下面是我的xml布局文件.我如何在屏幕中央对齐它.!!

I using a progress bar inside my layout. When I start the app the progress bar is always aligned to top left corner of screen. Below is my xml layout file. how can I align it on centre of the screen. !!

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/relativeLayout1"
    android:orientation="vertical"    
    android:background="#F1F1F1">

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
        <LinearLayout 
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:orientation="vertical"
           android:id="@+id/scrolllinear">

    <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/LinearLayout1"
                android:orientation="vertical"
                android:visibility="gone" > 

    <RelativeLayout android:id="@+id/layout_category1"
                android:padding="10.0dip"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10.0dip"
                android:layout_marginTop="10.0dip"
                android:layout_marginRight="10.0dip"
               android:clickable="false"
               android:descendantFocusability="blocksDescendants">

                <ImageView
                android:id="@+id/more_1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:src="@drawable/more"/>

                <TextView android:textSize="28.0sp"
                    android:id="@+id/tv_category1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="more 1"
                    android:layout_toLeftOf="@id/tv_see_more_1"
                    android:layout_alignParentLeft="true"
                    android:layout_centerVertical="true">
                </TextView>
    </RelativeLayout>

    <horizontalscrollview
        android:id="@+id/HMscrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/layout_category1">        

        <LinearLayout
            android:id="@+id/myLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_margin="5dp">
        </LinearLayout>
    </horizontalscrollview>
    </LinearLayout>


    <LinearLayout
        android:id="@+id/progLayout"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@null"
        android:visibility="gone"
        android:layout_gravity="center">

         **<ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"    
            android:indeterminateDrawable="@drawable/my_progress_indeterminate" >
         </ProgressBar>**
        </LinearLayout>
        <TextView 
            android:id="@+id/CheckTest"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="try again."
            android:visibility="gone"
            android:textSize="25.0sp"
            android:textStyle="bold"
            android:layout_marginTop="130dp"
            ></TextView>

   <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:id="@+id/LinearLayout2"
                android:visibility="gone" >

    <RelativeLayout android:id="@+id/layout_category2"
                android:padding="10.0dip"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10.0dip"
                android:layout_marginTop="10.0dip"
                android:layout_marginRight="10.0dip">

                <ImageView
                android:id="@+id/tv_see_more_2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:src="@drawable/more"/>

                <TextView android:textSize="28.0sp"
                    android:id="@+id/tv_category2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toLeftOf="@id/tv_see_more_2"
                    android:layout_alignParentLeft="true"
                    android:layout_centerVertical="true">
                </TextView>
    </RelativeLayout>


    <horizontalscrollview
        android:id="@+id/scrollViewHM2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/layout_category2">

        <LinearLayout
                    android:id="@+id/myLayout2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
        </LinearLayout>
    </horizontalscrollview>
    </LinearLayout>
    </LinearLayout>
    </ScrollView>
</RelativeLayout>

推荐答案

ScrollView 移除进度栏,并将其放置为父级布局的第一个子级,并使用 android:layout_centerInParent ="true"

Remove Progress bar from ScrollView and place it as the first child of parent layout and use android:layout_centerInParent="true"

  <RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/relativeLayout1"
        android:orientation="vertical"    
        android:background="#F1F1F1">

         <ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"    
            android:indeterminateDrawable="@drawable/my_progress_indeterminate"
            android:layout_centerInParent="true" >
         </ProgressBar>

        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
            <LinearLayout 
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:orientation="vertical"
               android:id="@+id/scrolllinear">

这篇关于显示屏幕进度条中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆