Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法使用viewpager查看表格布局_Android_Android Viewpager_Android Tablayout - Fatal编程技术网

Android 无法使用viewpager查看表格布局

Android 无法使用viewpager查看表格布局,android,android-viewpager,android-tablayout,Android,Android Viewpager,Android Tablayout,这是我将tablayout与viewpager链接的代码。它工作正常,但现在不工作。我无法查看设备中的选项卡布局。有人能告诉我是什么导致了这个问题吗?我认为我的代码是正确的 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"

这是我将tablayout与viewpager链接的代码。它工作正常,但现在不工作。我无法查看设备中的选项卡布局。有人能告诉我是什么导致了这个问题吗?我认为我的代码是正确的

<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:id="@+id/arootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.blipclap.creativegraphy.HomeActivity"
tools:showIn="@layout/app_bar_home">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"> 
</android.support.design.widget.TabLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_below="@+id/tabLayout"> 
</android.support.v4.view.ViewPager>

</RelativeLayout>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_gravity="bottom"
        app:layout_behavior=".Helper.BottomNavigationBehaviour"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/colorPrimary"
        app:itemIconTint="@android:color/background_dark"
        app:itemTextColor="@android:color/background_dark"
        app:menu="@menu/bottom_navigation_menu"> 
</android.support.design.widget.BottomNavigationView>


</android.support.design.widget.CoordinatorLayout>
这是我使用的活动代码

 viewPager = (ViewPager)findViewById(R.id.viewPager);
            MyFragmentAdapter adapter = new 
 MyFragmentAdapter(getSupportFragmentManager(), this);
            viewPager.setAdapter(adapter);

            tabLayout = (TabLayout) findViewById(R.id.tabLayout);
            tabLayout.setupWithViewPager(viewPager);
正如你所看到的,我看不到我手机中的标签布局,有什么问题吗

我的布局使用 所以,坐标布局是必要的,底部导航需要在外面,它应该是坐标布局的子级

我发现选项卡布局隐藏在应用程序栏后面

<android.support.constraint.ConstraintLayout 
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.blipclap.creativegraphy.HomeActivity">

<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"
        app:theme="@style/ToolbarColoredBackArrow" />

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

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


</android.support.constraint.ConstraintLayout>


试试这个,它会帮你的

<?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:id="@+id/arootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.TabLayout
        android:id="@+id/tab_host"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_red_light"> 
   </android.support.design.widget.TabLayout>
    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/tab_host"
        android:layout_above="@id/design_navigation_view"> 
   </android.support.v4.view.ViewPager>
    <android.support.design.widget.BottomNavigationView
        android:id="@+id/design_navigation_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@android:color/darker_gray"> 
   </android.support.design.widget.BottomNavigationView>
    </RelativeLayout>

解决这个问题的方法是

     <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
android:layout_marginTop="?attr/actionBarSize"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />


tab layout实际上在appbar下,所以我只是

尝试从
RelativeLayout
中取出
表格布局
,或者更好,删除
RelativeLayout
并将
LinearLayout
替换为
CoordinatorLayout
不起作用我尝试了两者都不起作用我无法更改协调器你可以看到我正在使用帮助器类但我更改了相对布局它说LinearLayout无效布局我编辑了问题你可以看到我的布局是包括在app_bar_layout中我可以使用下面的android:layout吗=“@+id/”我不认为你可以使用下面的
android:layout
,因为这是一个
ConstraintLayout
你需要重新安排你的约束,或者试着用
LinearLayout
替换
CoordinatorLayout
不起作用我无法更改协调器,你可以看到我正在使用帮助器类,但我更改了相对布局它说无效布局哪个帮助器类,你可以根据你修改帮助器类。若helper类和这个问题相关,那个么你们应该把它和这个问题一起发布。它仅适用于协调器布局。好的,您正在使用底部导航行为,请稍候,我为您的解决方案编辑了我的答案。我已编辑了问题,您是否可以看到我的布局包含在应用程序中?我可以使用下面的android:layout吗?=“@+id/”我已经编辑了这个问题,你可以看到我的布局包含在app_bar_layout中吗我可以使用android:layout_lower=“@+id/”
<?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:id="@+id/arootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.TabLayout
        android:id="@+id/tab_host"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_red_light"> 
   </android.support.design.widget.TabLayout>
    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/tab_host"
        android:layout_above="@id/design_navigation_view"> 
   </android.support.v4.view.ViewPager>
    <android.support.design.widget.BottomNavigationView
        android:id="@+id/design_navigation_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@android:color/darker_gray"> 
   </android.support.design.widget.BottomNavigationView>
    </RelativeLayout>
     <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
android:layout_marginTop="?attr/actionBarSize"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />