使进度条居中

时间:2017-04-21 09:33:19

标签: android layout progress-bar

我试图将我的进度条集中在fragements屏幕中。这是我到目前为止所尝试的内容,我认为应该是正确的:

ARToolKit for iOS

我尝试删除包装器布局,删除整个<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <ProgressBar android:id="@+id/pgFragment" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"/> </LinearLayout> <ScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="wrap_content" tools:listitem="@layout/recycler_row" /> </ScrollView> </LinearLayout> (但ScrollView设置为visibility时,它并不重要)。目前的结果是gone粘在屏幕顶部。

原因可能是因为活动布局实现了ProgressBar

NestedScrollView

3 个答案:

答案 0 :(得分:0)

像这样更新您的代码

<?xml version="1.0" encoding="utf-8"?>
<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">
    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:listitem="@layout/recycler_row" />

    </LinearLayout>
<ProgressBar
            android:id="@+id/pgFragment"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"/>
</RelativeLayout>

答案 1 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical">

        <ProgressBar
            android:id="@+id/pgFragment"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"/>

    </LinearLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />


</FrameLayout>

答案 2 :(得分:0)

请勿在{{1​​}}内使用RecyclerView。您已使用ScrollView作为容器NestedScrollView,因此您无需添加layout

更新您的XML,如下所示:

ScrollView

#。如果您想以<?xml version="1.0" encoding="utf-8"?> <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.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="wrap_content"> </android.support.v7.widget.RecyclerView> <RelativeLayout android:id="@+id/layoutProgress" android:layout_width="match_parent" android:layout_height="match_parent"> <ProgressBar android:id="@+id/pgFragment" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true"/> </RelativeLayout> </RelativeLayout> 的方式显示/隐藏prograssbarshowhide layoutProgresslayoutProgress.setVisibility(View.VISIBLE)方法。

希望这会有所帮助〜