问题描述
我正在使用带有4个标签的Android应用程序.
I'm working on an Android application with 4 tabs.
这是我的activity_main.xml
Here is my activity_main.xml
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
这是我的标签之一(目前它们都相同)
And here is one of my tab (they are all the same for the moment)
<?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="match_parent"
android:orientation="vertical"
android:background="#ff8400" >
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Top Screen"
android:textSize="20dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
如何添加在每个选项卡上可见的页脚?
How could I add a footer that would be visible on each tab?
要添加一个在滚动标签时仍可见的播放器.
It's to add a player that stays visible while scrolling the tab.
推荐答案
您将需要对您的主要活动布局进行更改.您可以使用LinearLayout或RelativeLayout做到这一点.因为LinearLayout的价格便宜,所以我在这里向您展示.
You're going to need to make a change to your main activity layout. You can do it with a LinearLayout or RelativeLayout. Because a LinearLayout is less expensive I will show you that here.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"/>
<View
android:id="@+id/music_player"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
该视图可以是任何东西,我建议在那里使用框架布局,如果要像音乐播放器一样复杂,则放入一个片段.这是如何工作的,您可以设置音乐播放器的高度(wrap_content),然后用layout_height ="0dp"和layout_weight ="1"告诉寻呼机占用其余空间.
The view could been anything, I would recommend using a framelayout there and putting in a fragment if it is going to be as complicated as a music player. How this works is you set the height of the musicplayer (wrap_content) and you tell the pager to take up the rest of the space with layout_height="0dp" and layout_weight="1".
如果您想执行RelativeLayout,则音乐播放器将alignParentBottom ="true",而传呼机将将layout_above ="@ + id/music_player设置为layout_height =" matchparent或alignParentTop =" true.
If you want to do a RelativeLayout then the musicplayer would alignParentBottom="true" and the pager would have layout_above="@+id/music_player with either layout_height="matchparent" or alignParentTop="true".
这篇关于片段应用程序,如何添加页脚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!