【发布时间】:2017-05-28 03:18:09
【问题描述】:
我想集成这样的东西:
我已经这样做了,但我似乎无法将 imageview 放在工具栏下方。没有工具栏,我可以让它在状态栏下,但是这两者结合起来是不可能的。
这是我的布局:
<?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>
在我的活动中,我做了以下事情:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
我还声明了一个 styles-v21.xml 文件:
<style name="Project.Photo" parent="Project.Light">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#59000000</item>
</style>
并将其设置为 PhotoActivity 的默认样式。 我已经尝试将工具栏放在 FrameLayout 中,但这样做我的工具栏只是隐藏起来,如下所示:
提前致谢。
已修复,但工具栏与状态栏重叠。无论如何要修复填充?如果我使用 android:fitsSystemWindows="true",状态栏不再是半透明的。
【问题讨论】:
-
不要忘记在每个版本的 android 上检查它,因为他们在每个主要版本都更改了 api。
-
在这里查看我的答案:stackoverflow.com/a/41707177/1543839
标签: android android-layout material-design android-toolbar android-statusbar