在 Android 中出现在整个屏幕上的 ProgressBar
ProgressBar appearing on whole screen in Android
我正在尝试在导航抽屉中实现 ProgressBar Activity,但它像这样覆盖了整个屏幕。
我尝试在 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_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" />
将 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>
终于完成了
创建新的 NavigationDrawer Activity 时,Android Studio 会生成 4 个 XML 文件。早些时候,我在 activity_home_screen.xml
中实现了 ProgressBar。现在在 content_home_screen.xml
中尝试实施后,它成功了
Note: HomeScreenActivity
is my Activity name
我的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>
我正在尝试在导航抽屉中实现 ProgressBar Activity,但它像这样覆盖了整个屏幕。
我尝试在 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_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" />
将 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>
终于完成了
创建新的 NavigationDrawer Activity 时,Android Studio 会生成 4 个 XML 文件。早些时候,我在 activity_home_screen.xml
中实现了 ProgressBar。现在在 content_home_screen.xml
中尝试实施后,它成功了
Note:
HomeScreenActivity
is my Activity name
我的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>