【发布时间】:2016-02-25 12:14:40
【问题描述】:
我有两种布局。第一个布局文件名为home.xml,第二个名为coordinator.xml。所以我只想在 coordinator.xml 中包含home.xml。但问题是当我尝试在coordinator.xml 中包含此布局时,它会跨越移动屏幕并进入其中。
如果我在我的包含布局中包含app:layout_behavior="@string/appbar_scrolling_view_behavior",它会跨越移动屏幕并进入其中。
如果我不包含此行为,它将与 Toolbar 重叠。
那么解决办法是什么?
home.xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="@+id/view"
android:layout_above="@+id/linear1"
android:background="#00409f"
android:layout_marginBottom="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/linear1"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:layout_height="wrap_content">
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:orientation="vertical"
android:gravity="center"
android:layout_height="wrap_content">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/home"/>
<TextView
android:layout_width="wrap_content"
android:textColor="#000000"
android:layout_height="wrap_content"
android:text="Home"/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:orientation="vertical"
android:gravity="center"
android:layout_height="wrap_content">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/wallet"/>
<TextView
android:layout_width="wrap_content"
android:textColor="#000000"
android:layout_height="wrap_content"
android:text="Wallet"/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:orientation="vertical"
android:gravity="center"
android:layout_height="wrap_content">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/qr_code"/>
<TextView
android:layout_width="wrap_content"
android:textColor="#000000"
android:layout_height="wrap_content"
android:text="QR Code"/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:orientation="vertical"
android:gravity="center"
android:layout_height="wrap_content">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/user_male"/>
<TextView
android:layout_width="wrap_content"
android:textColor="#000000"
android:layout_height="wrap_content"
android:text="Profile"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
coordinator.xml 代码:
<?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"
android:clickable="true"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context=".Home">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent" 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:contentInsetStart="0dp"
android:contentInsetLeft="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay">
<include layout="@layout/actionbar_layout"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<!--Include layout here give me problem-->
<include layout="@layout/home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>
app:layout_behavior="@string/appbar_scrolling_view_behavior" 看起来像这样:
没有app:layout_behavior="@string/appbar_scrolling_view_behavior",它看起来像这样:
【问题讨论】:
标签: android android-layout android-toolbar android-coordinatorlayout