我在一个具有以下布局的活动中添加了viewpager:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent"
android:weightSum="1">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="0.45">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1" />
</FrameLayout>
<android.support.v4.view.ViewPager
android:id="@+id/imgdetail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.15"
android:foregroundGravity="center_vertical|fill_vertical">
</android.support.v4.view.ViewPager>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container1"
android:layout_weight="0.4"></FrameLayout>
</LinearLayout>
但工具栏颜色已移动,并且viewpager已移至屏幕中心。
答案 0 :(得分:1)
以这种方式试试。只需指定元素的高度
即可<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="@+id/imgdetail"
android:layout_below="@id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foregroundGravity="center_vertical|fill_vertical">
</android.support.v4.view.ViewPager>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/container1"
android:layout_below="@id/imgdetail">
</FrameLayout></RelativeLayout>
答案 1 :(得分:1)
答案 2 :(得分:1)
使用RelativeLayout
轻松实现布局。使用RelativeLayout
并将ToolBar layout
设为顶级孩子,并将ViewPager
放在“工具栏布局”下方。
希望这有帮助。
此致
答案 3 :(得分:1)
试试这个布局
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
<android.support.v4.view.ViewPager
android:id="@+id/imgdetail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"/>
<FrameLayout
android:id="@+id/container1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"/>
</FrameLayout>