我刚刚创建了一个具有DrawerLayout的布局,其中有工具栏,tablayout和viewpager。然而,在tablayout中,标签在点击它们时没有响应,但在刷卡时正在改变。这是代码:
select p.pid, g.gid, DATE, DATE
在MainActivity.java中
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activities.HomeActivity">
<LinearLayout
android:id="@+id/main_layout"
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_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<!-- Content for screen without action bar-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@color/theme_color"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:background="@color/theme_color"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
app:tabIndicatorColor="@color/sub_theme_color"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@drawable/toolbar_shadow" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@id/tab_layout"/>
</FrameLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
app:headerLayout="@layout/header_navigation_drawer"
app:menu="@menu/menu_drawer_links"
/>
现在这里有一个奇怪的部分:它可以在Lollipop中点击,但不适用于棒棒糖前版本。
答案 0 :(得分:2)
您可以通过检查XML页面的“设计”选项卡中的布局视图来轻松解决此问题。最好将tablayout和viewpager放在relativelayout中。
活动很好。
以下是更正后的XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activities.HomeActivity">
<LinearLayout
android:id="@+id/main_layout"
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_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<!-- Content for screen without action bar-->
<!-- Move toolbar above drawerlayout so that on opening drawer, it is visible -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@color/theme_color"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/theme_color"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
app:tabIndicatorColor="@color/sub_theme_color"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<View
android:id="@+id/shadow_toolbar"
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@drawable/toolbar_shadow" />
</RelativeLayout>
</FrameLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
app:headerLayout="@layout/header_navigation_drawer"
app:menu="@menu/menu_drawer_links"
/>
</android.support.v4.widget.DrawerLayout>