我在MainActivity
中有一个标签布局,其ViewPager
,我也在向MainActivity
添加底部导航,我希望ViewPager
的高度接近 <android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<TextView
android:id="@+id/logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10sp"
android:paddingTop="10sp"
android:textAlignment="center"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="40sp"
android:text="@string/app_name" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="top"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<include layout="@layout/bottom_nav"></include>
</android.support.design.widget.CoordinatorLayout>
顶部导航的顶部。
这是我的主要活动布局
ViewPager
目前Viewpager
跨越底部导航栏后面的全高。我希望我的Error:error: linker command failed with exit code 1 (use -v to see invocation)
如下所示
答案 0 :(得分:1)
使用LinearLayout
作为父级布局,并为ViewPager
设置权重。它适用于你的情况。检查以下代码。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<TextView
android:id="@+id/logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10sp"
android:paddingTop="10sp"
android:textAlignment="center"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="40sp"
android:text="@string/app_name" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="top"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<include layout="@layout/bottom_nav"></include>
</LinearLayout>
答案 1 :(得分:0)
在坐标布局后使用Liner布局作为父布局。
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<TextView
android:id="@+id/logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10sp"
android:paddingTop="10sp"
android:textAlignment="center"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="40sp"
android:text="@string/app_name" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="top"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<include layout="@layout/bottom_nav"></include>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>