ProgressBar出现在Android的整个屏幕上

问题描述 投票:2回答:3

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

enter image description here

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

我们是cML圆角

<?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不重复

android android-progressbar
3个回答
1
投票

终于完成了

在创建新的NavigationDrawer Activity时,Android Studio会生成4个XML文件。之前我在activity_home_screen.xml实施了ProgressBar。现在尝试在content_home_screen.xml实施后,它起作用了

注意:HomeScreenActivity是我的活动名称

我的content_home_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>

0
投票

这是因为进度条的硬编码大小

android:layout_width =“100dp”android:layout_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" />

0
投票

将ProgressBar放在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>
© www.soinside.com 2019 - 2024. All rights reserved.