如果位于工具栏上方,则水平进度条不可见(对于Android 5) [英] Horizontal progress bar is not visible if placed above toolbar (For Android 5)

查看:85
本文介绍了如果位于工具栏上方,则水平进度条不可见(对于Android 5)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过使用以下XML将水平进度栏放置在工具栏的顶部.

I tried to place horizontal progress bar on the top of toolbar by having the following XML.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <!-- Toolbar -->
        <include layout="@layout/toolbar"/>

        <!-- http://stackoverflow.com/questions/14171471/remove-vertical-padding-from-horizontal-progressbar -->
        <ProgressBar
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="8dp"
            android:id="@+id/progress_bar"
            android:layout_gravity="top"

            android:layout_marginBottom="0dp"
            android:layout_marginTop="-3dp"

            android:progress="2000"
            android:max="10000" />

    </FrameLayout>

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ProgressBar
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="8dp"
            android:id="@+id/progress_bar2"
            android:layout_gravity="top"

            android:layout_marginBottom="0dp"
            android:layout_marginTop="-3dp"

            android:progress="2000"
            android:max="10000" />

    </FrameLayout>
</LinearLayout>

toolbar.xml

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:elevation="4dp"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >

    <!-- android:elevation="4dp" is used due to http://www.google.com/design/spec/what-is-material/elevation-shadows.html#elevation-shadows-elevation-android- -->

</android.support.v7.widget.Toolbar>

这在Android 4+上绝对可以正常工作.这是Android 4+的屏幕截图

This works absolutely fine under Android 4+. Here's the screenshot for Android 4+

但是,对于Android 5+,水平进度条在工具栏顶部不可见.

However, when it comes to Android 5+, the horizontal progress bar is not visible on the top of toolbar.

如果我删除行

<include layout="@layout/toolbar"/>

我将在Android 5+中获得以下屏幕截图

I will get the following screenshot in Android 5+

似乎顶部的进度栏被工具栏阻止了?但是,我认为在 FrameLayout 中,进度栏的z顺序比工具栏的顺序高?

It seems that the top progress bar is blocked by toolbar? But, I thought within FrameLayout, the progress bar is having higher z-order than toolbar?

我可以知道,如果在Android 5+中,如何将水平进度条显示在工具栏上方

May I know, how I can make horizontal progress bar visible if placed above toolbar, in Android 5+

推荐答案

在Android 5.0及更高版本的设备上,确定组件的z顺序时会考虑到海拔高度-海拔较高的组件明显高于海拔较低的组件,即使较高海拔的项目在XML文件中声明得较早(通常会导致其落后).

On Android 5.0+ devices, elevation is taken into account when determining the z-order of components - those with a higher elevation are visibly above those with a lower elevation, even if the higher elevation item is declared earlier in the XML file (normally causing it to be behind).

您可以在 ProgressBar 中添加一个高程,与 Toolbar 的高程相匹配-这样可以确保与以前的Android版本中的z顺序相同.

You can add an elevation to your ProgressBar, matching the elevation of the Toolbar - that will ensure that the same z-ordering works as in previous versions of Android.

这篇关于如果位于工具栏上方,则水平进度条不可见(对于Android 5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆