选项卡栏和导航抽屉对齐

14

我正在尝试制作一个应用程序,其中选项卡栏、导航抽屉和搜索都在工具栏下方,但当我尝试在选项卡栏中执行时,页面标题会被分开this is comming,我想显示其他片段的标题

布局代码
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Boss.Main2Activity">

<android.support.design.widget.CoordinatorLayout

    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/bg_img"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY" />


    <com.antonyt.infiniteviewpager.InfiniteViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <me.alexrs.fontpagertitlestrip.lib.FontPagerTitleStrip
            android:id="@+id/titlestrip"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_marginEnd="50dp"
            android:layout_marginStart="50dp"
            android:background="@color/material_fragment_top"

            app:fontFamily="@font/font"

            app:theme="@style/AppTheme.PopupOverlay" />

    </com.antonyt.infiniteviewpager.InfiniteViewPager>


<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="50dp"

    app:theme="@style/CustomActionBar" />

<include layout="@layout/content_main2" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

我希望布局可以展示导航抽屉、选项卡栏、搜索栏图标以及页面标题,将导航抽屉和搜索栏之间的距离缩短,使它们看起来更加紧凑。我想让工具栏的样式类似于黑色播放器应用


尝试帮助您,但似乎InfiniteViewPager库已损坏 https://github.com/antonyt/InfiniteViewPager/issues/35 - Duna
@Lunatikul 先生,如果我将无限视图页面更改为普通视图页面,您能帮助我吗? - Neelay Srivastava
@Lunatikul 如果您可以使用简单的ViewPager完成它,那也会被视为答案。 - Neelay Srivastava
你使用过Android的默认导航活动吗?如果是的话,那么你需要更改在XML中创建的appBar的布局。我已经为此编写了代码,但我只需要确认您是否使用了默认的导航活动。 - Harsh Jain
如果您需要,我可以将主要活动代码也放在这里。 - Neelay Srivastava
显示剩余8条评论
1个回答

4
现在我在Black Player应用程序中看到的是,您想要完全相同的标题是自定义的。从我的角度来看,导航按钮不是默认按钮,而是一个图像,单击抽屉将打开和关闭。因此,在下面给出的XML中,我只是创建了一个自定义顶部栏,即RelativeLayout,在这种情况下,它具有操作栏的默认高度。 现在你只需要在java文件中做一件事,就是从那里隐藏工具栏,这样自定义的topBar就会自动出现在其上方。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    tools:context="com.bodaciousithub.myapplication.Main5Activity">

    <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="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:src="@drawable/ic_menu_black_24dp"
            android:layout_centerVertical="true"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_toRightOf="@id/imageView"
            android:background="?attr/colorPrimary"
            android:layout_toLeftOf="@id/imageView2"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            android:layout_toEndOf="@id/imageView"
            android:layout_toStartOf="@id/imageView2"
            app:tabMode="scrollable">
            <android.support.design.widget.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Tab1"/>
            <android.support.design.widget.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Tab2"/>
            <android.support.design.widget.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Tab3"/>

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

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:src="@drawable/ic_search_black_24dp"
            android:layout_alignParentEnd="true"
            android:layout_marginRight="8dp"
            android:layout_alignParentRight="true" />

    </RelativeLayout>


    <include layout="@layout/content_main5" />

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

最后一个include布局语句是添加显示内容的主要布局。AppBar Layout是默认的导航视图中包含的组件,因此在Java文件中我已将其隐藏。您可以编写getSupportActionBar().hide()getActionBar().hide()来实现。下面是我制作的布局截图。

Screen Image

希望有所帮助!

我使用了选项卡布局,因为它与视图翻页器一起使用会更容易,但如果你有其他想法,可以尝试一下!@Neelay Srivastava - Harsh Jain
@NeelaySrivastava 那有帮助吗? - Harsh Jain
@NeelaySrivastava 没问题,但它有帮助吗! - Harsh Jain
兄弟,问题是我没有以那种方式看待它,因为我不使用选项卡布局。我必须删除无限视图分页器。 - Neelay Srivastava
兄弟,我需要一些帮助。我正在使用TabLayout中的样式来改变字体的样式和大小,但它只在横屏模式下起作用,其他模式下不起作用。你有什么想法吗? - Neelay Srivastava
显示剩余7条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接