代码之家  ›  专栏  ›  技术社区  ›  Kartik Agarwal

Android全屏幕出现ProgressBar

  •  2
  • Kartik Agarwal  · 技术社区  · 6 年前

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

    enter image description here

    style="?android:attr/progressBarStyleSmall" 在我的ProgressBar里但没有成功

    <?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 ProgressBar size take whole screen

    3 回复  |  直到 6 年前
        1
  •  1
  •   Kartik Agarwal    6 年前

    当创建新的NavigationDrawer活动时,androidstudio生成4个XML文件。早些时候我在 activity_home_screen.xml . 在尝试在 content_home_screen.xml

    注: HomeScreenActivity 是我的活动名称

    我的 文件

    <?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>
    
        2
  •  0
  •   Sunny    6 年前

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

    android:布局宽度=“100磅”android:布局高度=“100磅”

    试试这个:

    <ProgressBar
            android:id="@+id/progressBar1"
            style="?android:attr/progressBarStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true" />
    
        3
  •  0
  •   TheWanderer    6 年前

    <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>