【问题标题】:Fragment application, how to add a footer?片段应用程序,如何添加页脚?
【发布时间】:2014-01-03 22:28:04
【问题描述】:

我正在开发一个带有 4 个选项卡的 Android 应用程序。

这是我的 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>

这是我的一个标签(目前它们都一样)

 <?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>

如何添加在每个选项卡上可见的页脚?

这是添加一个在滚动标签时保持可见的播放器。

【问题讨论】:

    标签: java android android-fragments tabs


    【解决方案1】:

    您将需要对主要活动布局进行更改。您可以使用 LinearLayout 或 RelativeLayout 来实现。因为 LinearLayout 比较便宜,所以我会在这里展示给你看。

    <?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" 占据其余空间。

    如果您想做一个 RelativeLayout,那么音乐播放器将 alignParentBottom="true" 并且寻呼机将 layout_above="@+id/music_player 与 layout_height="matchparent" 或 alignParentTop="true"。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-18
      • 2013-10-16
      • 2012-03-13
      • 1970-01-01
      • 2014-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多