Android中出现在整个屏幕上的ProgressBar

Android中出现在整个屏幕上的ProgressBar,android,android-progressbar,Android,Android Progressbar,我试图在导航抽屉活动中实现ProgressBar,但它像这样覆盖了整个屏幕 我尝试在ProgressBar中设置style=“?android:attr/progressBarStyleSmall”,但没有成功 我的XML文件 <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/r

我试图在导航抽屉活动中实现ProgressBar,但它像这样覆盖了整个屏幕

我尝试在ProgressBar中设置
style=“?android:attr/progressBarStyleSmall”
,但没有成功

我的XML文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_home_screen"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_home_screen"
        app:menu="@menu/activity_home_screen_drawer" />

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerHorizontal="true" />

</android.support.v4.widget.DrawerLayout>


这是由于进度条的硬编码大小造成的

android:layout\u width=“100dp”android:layout\u height=“100dp”

试试这个:

<ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true" />

将进度条放在NavigationView中:

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_home_screen"
    app:menu="@menu/activity_home_screen_drawer">

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerHorizontal="true" />

</android.support.design.widget.NavigationView>

终于完成了

创建新的NavigationDrawer活动时,Android Studio生成4个XML文件。早些时候,我在
activity\u home\u screen.xml
中实现了ProgressBar。现在,在尝试在
content\u home\u screen.xml中实现后,它成功了

注:
HomeScreenActivity
是我的活动名称

我的
content\u home\u screen.xml
文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".HomeScreenActivity"
    tools:showIn="@layout/app_bar_home_screen">

    <LinearLayout
        android:id="@+id/header_search"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal"
        android:paddingEnd="16dp"
        android:weightSum="5">

       <!-- Some Code.... -->

    </LinearLayout>

    <View
        android:id="@+id/content_view"
        android:layout_width="wrap_content"
        android:layout_height="2dp"
        android:layout_below="@id/header_search"
        android:background="@drawable/gradient_view" />

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerInParent="true" />

</RelativeLayout>


在这里的任何地方都有相同的想法,但在
抽屉布局中
实现后,此进度条不会显示在屏幕上,它现在应该显示在抽屉布局中@KartikAgarwal。但是没有保证,因为你不应该这样做。看起来唯一的选择可能是获取header视图,并以编程方式将进度条添加到headeryes,现在进度条将进入抽屉标题。但我不想要这个。谢谢你的建议,根据答案,你应该可以在里面放一个自定义视图。尝试将进度条包装为线性布局。您的布局不正确,请参阅。