android - 如何在viewpager的选项卡上方添加按钮

标签 android android-fragments android-viewpager swipeview

我使用“android.support.v4.view.ViewPager”和“android.support.v4.view.PagerTitleStrip”创建了一个带有滑动的选项卡 View 。现在我需要在标题栏顶部显示一个按钮或 TextView 。即使我在标题栏上方添加 TextView ,它也不会显示。我的 xml 文件如下。

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"  
xmlns:tools="http://schemas.android.com/tools"  
android:id="@+id/pager"  
android:layout_width="match_parent"  
android:layout_height="match_parent"  
tools:context=".MainActivity"
android:background="@drawable/home_background11" >  

<TextView
            android:id="@+id/label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello"/>  

<android.support.v4.view.PagerTitleStrip  
android:id="@+id/pager_title_strip"  
android:layout_width="match_parent"  
android:layout_height="wrap_content"  
android:layout_gravity="top"  
android:background="#33b5e5"  
android:paddingBottom="4dp"  
android:paddingTop="4dp"  
android:textColor="#fff" />  

</android.support.v4.view.ViewPager> 

最佳答案

为什么要尝试将TextView放入ViewPager中?也许我的代码会对你有所帮助:

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:text="Hello" />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignBottom="true"
        android:layout_below="@id/label"
        android:background="@drawable/home_background11"
        tools:context=".MainActivity" >

        <android.support.v4.view.PagerTitleStrip
            android:id="@+id/pager_title_strip"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:background="#33b5e5"
            android:paddingBottom="4dp"
            android:paddingTop="4dp"
            android:textColor="#fff" />
    </android.support.v4.view.ViewPager>

</RelativeLayout>

关于android - 如何在viewpager的选项卡上方添加按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16916067/

相关文章:

java - 切换fragment时如何维护fragment状态

android - fragment 替换事务不记住可变位图的状态

java - 使 ViewPager 的高度等于 PagerAdapter 中最高的项目

android - 无法使用 Android Studio 打开现有项目

跨 DAO 的 Android Room 交易

android - NotificationPreferenceFragment - 默认构造函数已弃用

android - 动态改变 Fragment 的容器高度

c# - 将 AcquireCameraImageBytes() 从 Unity ARCore 保存为图像存储

java - 我不知道我的错误在哪里 appcompat :design:1. 1.0

java - 带有 ViewPager 的 Android ClassNotFoundException