gpt4 book ai didi

android - 如果放置在工具栏上方,则水平进度条不可见(适用于 Android 5)

转载 作者:太空宇宙 更新时间:2023-11-03 12:05:37 24 4
gpt4 key购买 nike

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

我的 Activity .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>

工具栏.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+ 的屏幕截图

enter image description here

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

enter image description here

如果我删除行

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

我在Android 5+中会得到如下截图

enter image description here

顶部进度条好像被toolbar挡住了?但是,我认为在 FrameLayout 中,进度条的 z 顺序比工具栏高?

我可以知道吗,如果在 Android 5+ 中将水平进度条放在工具栏上方,我该如何使水平进度条可见

最佳答案

在 Android 5.0+ 设备上,在确定组件的 z 顺序时会考虑海拔 - 海拔较高的组件明显高于海拔较低的组件,即使在 XML 文件中较早声明了海拔较高的项目(通常导致它落后)。

您可以向您的 ProgressBar 添加高度,匹配 Toolbar 的高度 - 这将确保相同的 z 顺序与以前版本的 Android 中一样工作。

关于android - 如果放置在工具栏上方,则水平进度条不可见(适用于 Android 5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32464749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com