【问题标题】:How to place tab layout after toolbar?如何在工具栏之后放置选项卡布局?
【发布时间】:2016-09-07 15:52:50
【问题描述】:

我在片段中有一个 tablayout 和一个 viewpager。我的标签布局中有两个标签。和我的 app_bar_main.xml 中的工具栏。但是当我运行我的应用程序时,tablayout 隐藏了工具栏。它如何放置在工具栏之后? 这是我的代码 这是我的 app_bar_main.xml 文件

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#CC0000"
        android:titleTextColor="@color/white"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<FrameLayout
    android:id="@+id/fragment_containerlayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF"></FrameLayout>

这是我的片段设计,我在其中放置了选项卡布局和视图寻呼机

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.nayab.demotask.ContactsFragment"
xmlns:app="http://schemas.android.com/apk/res-auto">


<android.support.design.widget.TabLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/contactstablayot"
    android:layout_gravity="left|top"
    android:background="#000000"
    app:tabTextColor="@android:color/white"
    />

<android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/fragviewpager"
    android:layout_gravity="left|center_vertical"
    android:layout_marginTop="30dp"
    android:background="#e6f1f5"
    />

谁能帮帮我

【问题讨论】:

  • 你想在这里实现什么?只有一个屏幕,顶部有工具栏,下方有标签布局?

标签: android xml android-viewpager toolbar android-tablayout


【解决方案1】:

尝试在您的 Framelayout 上使用 app:layout_behavior="@string/appbar_scrolling_view_behavior"

【讨论】:

    【解决方案2】:

    你可以使用垂直方向的线性布局

    <?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.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">
    
           <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="#CC0000"
                android:titleTextColor="@color/white"
                app:popupTheme="@style/AppTheme.PopupOverlay" />
    
        </android.support.design.widget.AppBarLayout>
    
        <FrameLayout
            android:id="@+id/fragment_containerlayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"></FrameLayout>
    
    </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-20
      • 1970-01-01
      • 2017-08-22
      • 1970-01-01
      • 2017-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多