问题描述
我想集成这样的东西:
我已经这样做了,但是我似乎无法将imageview放在工具栏下面.没有工具栏,我可以在状态栏下创建它,但是将这两个部分组合是不可能的.
And I've done it like this, but I can't seem to put the imageview below the toolbar. Without the toolbar, I can make it under the status bar, but combining these two are impossible.
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true"
tools:context="com.project.android.PhotoActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/photo_tl"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#59000000"
tools:ignore="UnusedAttribute" />
<ImageView
android:id="@+id/photo_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitStart" />
</LinearLayout>
在我的活动中,我完成了以下操作:
In my activity, I've done the following:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
我还声明了一个styles-v21.xml文件:
I've also declared an styles-v21.xml file:
<style name="Project.Photo" parent="Project.Light">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#59000000</item>
</style>
并将其设置为PhotoActivity的默认样式.我已经尝试过将工具栏放置在FrameLayout中,但是这样做会隐藏我的工具栏,就像这样:
And set it as default style for PhotoActivity.I've already tried putting the toolbar in a FrameLayout, but doing that my toolbar simply hides, like this:
谢谢.
已解决,但工具栏与状态栏重叠.反正有修复填充?如果我使用android:fitsSystemWindows ="true",则状态栏不再透明.
推荐答案
如您所说,
与此相关的问题是在FrameLayout
中添加childView的顺序,您将工具栏添加为第一个孩子,然后添加了ImageView.这就是图像隐藏工具栏的原因.取而代之的是,FameLayout
内的视图顺序应为
The problem with this is the order of adding childView in FrameLayout
, you added Toolbar as first child and after that you added ImageView. this is why image hides the toolbar. Instead, the order of views inside FameLayout
should be like this
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.project.android.PhotoActivity">
<ImageView
android:id="@+id/photo_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitStart" />
<android.support.v7.widget.Toolbar
android:id="@+id/photo_tl"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#59000000"
tools:ignore="UnusedAttribute" />
</FrameLayout>
对于API级别> = 19,也可以在style.xml
文件中添加此属性,以使statusBar透明<item name="android:windowTranslucentStatus">true</item>
要在statusBar后面制作内容,请使用此链接
https://developer.android.com/training/system -ui/status.html#behind
Also for API level >=19 ,you can add this attribute in style.xml
file to make statusBar transparent<item name="android:windowTranslucentStatus">true</item>
For making content behind statusBar use this link
https://developer.android.com/training/system-ui/status.html#behind
这篇关于半透明的状态栏和工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!