【问题标题】:android pager tab strip in bottom taking entire fragment底部的android寻呼机标签条带走整个片段
【发布时间】:2023-04-08 08:39:02
【问题描述】:

我想看看 首先会在片段上显示广告视图,最后会出现 botton android pagertabstrip,但 pagertabstip 会以某种方式占据整页。 我的代码在下面

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black" >

<LinearLayout
    android:id="@+id/adview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/black"
    android:orientation="vertical" >
</LinearLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/tabs"
    android:layout_below="@+id/adview"
    tools:context=".MainActivity" />

<com.astuetz.PagerSlidingTabStrip
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="48dip"
    android:layout_alignParentBottom="true"
    android:layout_below="@+id/adview"
    android:background="@color/black" >
</com.astuetz.PagerSlidingTabStrip>

</RelativeLayout>

我如何做到这一点,标签条底部和分页器视图顶部,

【问题讨论】:

    标签: android android-fragments pager


    【解决方案1】:

    您应该使用layout_gravity="bottom",因为ViewPager 扩展了FrameLayout,所以它与FrameLayout 使用的参数相同。 android:layout_alignParentBottom 代表RelativeLayout

    编辑:

    重新阅读您的问题和您的 XML。我以为你使用的是标准的PagerTabStrip from the support library,但这就是你想要的:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/black" >
    
    <LinearLayout
        android:id="@+id/adview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/black"
        android:orientation="vertical" >
    </LinearLayout>
    
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/tabs"
        android:layout_below="@+id/adview"
        tools:context=".MainActivity" />
    
    <com.astuetz.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="48dip"
        android:layout_alignParentBottom="true"
        android:background="@color/black" >
    </com.astuetz.PagerSlidingTabStrip>
    
    </RelativeLayout>
    

    从标签中删除android:layout_below="@+id/adview"。它使标签在 adview 之后立即启动。

    【讨论】:

    • 嗨,它是相对布局,因为我想在片段上显示浮动
    • 我读错了你的问题,我编辑了我的答案。现在应该是正确的。
    • 非常感谢,它就像魔法一样工作,似乎我不明白相对视图是如何工作的:(
    • 它有效!但是,有一种方法可以将 'underline' 选择器设置为 'upperline'?
    【解决方案2】:

    使用这个:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black"
    android:orientation="vertical" >
    
    <LinearLayout
        android:id="@+id/adview"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/black"
        android:orientation="vertical" >
    </LinearLayout>
    
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.9"
        android:background="#ff0000"
        tools:context=".MainActivity" />
    
    <com.astuetz.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.1"
        android:background="@color/black" >
    </com.astuetz.PagerSlidingTabStrip>
    
    </LinearLayout>
    

    【讨论】:

    • 它也有效,但 adview 不能在 viewpager 上浮动。感谢帮助我
    【解决方案3】:

    使用 - layout_gravity="bottom"

    为什么?因为,FrameLayoutViewPager 扩展了

    【讨论】:

    • 嗨,它是相对布局,因为我想在片段上显示浮动,
    猜你喜欢
    • 1970-01-01
    • 2013-08-04
    • 1970-01-01
    • 2016-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多