好像这个问题以前被问过很多次了。至少我在互联网上发现了很多,尤其是 SO。但是没有一个答案有帮助,不知道为什么。
我在 Android Studio 2.2.2 中创建了一个简单的空白选项卡式活动项目,除了添加一个图像视图外,没有触及其中的任何内容。这是生成的活动布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.company.me.navbartest.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
这里没有改变任何东西。这是一个片段的布局:
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.company.me.navbartest.MainActivity$PlaceholderFragment">
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:layout_alignParentBottom="true"
android:src="@mipmap/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
这里唯一添加的是片段底部的 ImageView。根本没碰过代码。不知道是否需要它,但以防万一它在这里: http: //pastebin.com/FuUiGpyH
这是在 KitKat 上拍摄的,但在 Marshmallow 上也是如此。看到绿色的小耳朵了吗?那来自我添加的 ImageView。这是一个安卓标志的图标。
我尝试了“fitsSystemWindows”标志的不同组合。没有成功。我想我只是不太明白它是如何工作的,应该使用它。
还尝试更改片段的根对象 - 结果相同。
所以主要问题是 - 如何解决这个问题?如何确保这个 ImageView 显示在它应该显示的位置?
gradle 规格是:
minSdkVersion 19
targetSdkVersion 25
compileSdkVersion 25
buildToolsVersion "25.0.0"
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'