Viewpager及其顶部的导航栏
问题描述:
看来,这个问题之前曾被提过很多次。 至少我在互联网上找到了很多东西,特别是它。 但没有任何答案有帮助,不知道为什么。Viewpager及其顶部的导航栏
我在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
这是采取奇巧,但它同样的棉花糖。 看到绿色的小耳朵?这来自我添加的ImageView。这是一个android徽标的图标。我试过不同的“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'
答
看起来像我找到了解决办法。
“问题”出现在工具栏的滚动标志中。我猜的模板应该用一个列表和具体的滚动(就是一个工具栏处于折叠状态)被使用,因此标志是
scroll | enterAlways
但我的传呼机没有任何名单,并没有应该是可滚动的,所以我只是删除它们,现在一切都正常!
另一个“解决方法”是在LinearLayout中包围AppBarLayout。也有帮助,但不知道副作用。没有太多的测试。
尝试使用'adjustViewBounds =“true”'和'scaleType =“fitXY”' –
您可以将底部边距添加到您的图像视图 –
这不会解决真正的问题。我的意思是ImageView只是这种情况下任何控件的示例。想象有一个EditText而不是它。或另一个视图组。 –