Android recyclerview上的第一项堆叠到选项卡布局

Android recyclerview上的第一项堆叠到选项卡布局,android,Android,我已经检查了xml文件,但是(对我来说)一切都正常,但是视图仍然堆积在一起。我也收到了这样的错误信息 播放片段:onResponse:hasil Pemanggilan改装2.2.1适配器工厂$ExecutorCallbackCall@1c95dee5 下面是关于我的PlayingFramgment课程的内部回应 private void bacaData(){ progressBar.setVisibility(View.VISIBLE); final Recy

我已经检查了xml文件,但是(对我来说)一切都正常,但是视图仍然堆积在一起。我也收到了这样的错误信息

播放片段:onResponse:hasil Pemanggilan改装2.2.1适配器工厂$ExecutorCallbackCall@1c95dee5

下面是关于我的PlayingFramgment课程的内部回应

private void bacaData(){
        progressBar.setVisibility(View.VISIBLE);
        final RecyclerView rvCategory = getActivity().findViewById(R.id.playing_daftar);
        rvCategory.setLayoutManager(new LinearLayoutManager(getActivity()));

        ApiInterface apiInterface = ApiClient.getRetrofit(getContext()).create(ApiInterface.class);
        Call<MovieResponse> call = apiInterface.getNowPlaying();
        call.enqueue(new Callback<MovieResponse>() {
            @Override
            public void onResponse(Call<MovieResponse> call, Response<MovieResponse> response) {
                MovieResponse data = response.body();
                if (data.getResults().size() == 0){
                    Toast.makeText(getContext(), "Maaf data yang anda cari tidak ditemukan",
                            Toast.LENGTH_SHORT).show();
                    progressBar.setVisibility(View.GONE);
                } else {
                    rvCategory.setAdapter(new MoviesAdapter(data.getResults(), R.layout.list_movie_row, getContext()));
                    Log.d(TAG, "onResponse: hasil pemanggil" + call);
                    progressBar.setVisibility(View.GONE);
                }
            }

            @Override
            public void onFailure(Call<MovieResponse> call, Throwable t) {
                Toast.makeText(getContext(), "Gagal", Toast.LENGTH_SHORT).show();
                Log.d(TAG, t.toString());
                progressBar.setVisibility(View.GONE);
            }
        });
    }
private void bacaData(){
progressBar.setVisibility(View.VISIBLE);
final RecyclerView rvCategory=getActivity().findViewById(R.id.playing_daftar);
rvCategory.setLayoutManager(新的LinearLayoutManager(getActivity());
ApiInterface ApiInterface=ApiClient.GetReformation(getContext()).create(ApiInterface.class);
Call Call=apinterface.getNowPlaying();
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
MovieResponse data=response.body();
if(data.getResults().size()==0){
Toast.makeText(getContext(),“没有数据的Maaf数据”,
吐司。长度(短)。show();
progressBar.setVisibility(View.GONE);
}否则{
rvCategory.setAdapter(新的MoviesAdapter(data.getResults(),R.layout.list_movie_row,getContext());
Log.d(标签“onResponse:hasil pemanggil”+呼叫);
progressBar.setVisibility(View.GONE);
}
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
Toast.makeText(getContext(),“Gagal”,Toast.LENGTH_SHORT.show();
Log.d(TAG,t.toString());
progressBar.setVisibility(View.GONE);
}
});
}
我发布了xml布局片段

<RelativeLayout 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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".fragment.PlayingFragment">

    <!-- TODO: Update blank fragment layout -->

        <android.support.v7.widget.RecyclerView
            android:id="@+id/playing_daftar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/progressMainBar"
        android:layout_centerInParent="true"/>

</RelativeLayout>

fragment_播放是fragment_home的一部分,下面是代码

<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
    android:orientation="vertical"
    tools:context=".BlankFragment">

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

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlways"
            app:tabGravity="fill"
            app:tabIndicatorColor="@color/colorAccent"
            app:tabMode="fixed"
            app:tabSelectedTextColor="#ffffff">

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

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/appbar"
            android:padding="@dimen/activity_vertical_margin" />
    </FrameLayout>

</LinearLayout>

我把片段放进了内容主目录

<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:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".MainActivity"
    tools:showIn="@layout/app_bar_main">

    <android.support.v4.view.ViewPager
        android:layout_below="@+id/toolbar"
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</RelativeLayout>

content_main是app_bar_main的一部分

<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:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

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

        <android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorPrimaryDark"
            app:tabTextColor="@color/colorAccent"
            app:tabSelectedTextColor="@color/colorAccent"
            android:id="@+id/tabs">

            <android.support.design.widget.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/tab_np"
                android:text="@string/now_playing"
                android:textColor="@color/colorAccent"/>

            <android.support.design.widget.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/up_coming"
                android:id="@+id/tab_up"/>

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

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

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

</RelativeLayout>

由于您使用RelativeLayout作为根组件,因此必须为RecyclerView提供页边顶部:

android:layout_marginTop="104dp"
编辑:

如果您使用coordinatorLayout作为根布局,则情况会有所不同

编辑

以下问题在您的代码中很明显:

1-片段主页中的AppBarLayout是额外的,因为您在activitie的主页布局中已经有一个Appbar

2-根据android官方文件,使用CoordinatorLayout代替RelativeLayout。通过使用RelativeLayout,您将失去AppBarLayout的一些功能和布局管理

3-由于您刚刚在app\u bar\u main中包含了content\u main,因此无需使用
tools:context=“.MainActivity”
tools:showIn=“@layout/app\u bar\u main”

4-用合并标记替换content_main中的RelativeLayout

在进行上述更改后,您刚刚删除了可能对页边距和焊盘产生副作用的额外布局,然后将下面的属性应用于您的视图寻呼机。我希望这些更改将有效,并且代码中没有其他隐藏项:

android:layout_marginTop="104dp"

您应该使用下方的
属性,使您的viewPager位于上方选项卡下方。我认为您的viewPager的高度和宽度都是匹配的

将您的Relativelayout更改为android.support.design.widget.CoordinatorLayout,并将app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”添加到android.support.v7.widget.RecyclerView

试试这种方法。。 生成viewpager xml代码

<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:fitsSystemWindows="true">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/tab_bg_color"
    android:orientation="vertical">
    <android.support.design.widget.TabLayout
        android:id="@+id/tlConversation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        app:tabIndicatorColor="@color/tab_color"
        app:tabMinWidth="0dp"
        app:tabMode="fixed"
        app:tabTextAppearance="@style/Tab_Style"
        app:tabSelectedTextColor="@color/tab_color"
        app:tabTextColor="@color/tab_text_color">

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

    <android.support.v4.view.ViewPager
        android:id="@+id/vpPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white">

    </android.support.v4.view.ViewPager>
</LinearLayout>

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

在调用上述方法之后,类似这样的方法设置为tablayout

  setupViewPager(viewPager);
    tabLayout.setupWithViewPager(viewPager);

将此用于应用程序\u mar\u main:

<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:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/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="wrap_content"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorPrimaryDark"
            app:tabTextColor="@color/colorAccent"
            app:tabSelectedTextColor="@color/colorAccent"
            android:id="@+id/tabs">

            <android.support.design.widget.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/tab_np"
                android:text="@string/now_playing"
                android:textColor="@color/colorAccent"/>

            <android.support.design.widget.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/up_coming"
                android:id="@+id/tab_up"/>

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

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

    <include layout="@layout/content_main"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_below="@+id/appbarlayout"
        android:layout_marginTop="1dp"/>

</RelativeLayout>


发布xml…@mTak完成。我已经发布了xml代码,仅此一项是没有用的。你需要将活动的xml发布到问题所在的地方,ishey@mTak我已经放置了另一个xml代码app:layout_behavior=“@string/appbar_scrolling_view_behavior”这与android.support.design.widget.CoordinatorLayuti一起工作。我更果断地检查了你的问题,你写得太乱了,试图让它整洁。我想让它整洁,然后在这个问题下面给你一个答案。考虑编辑2:请从结果中知道我。你的取景器在标签下面吗?或者您可以发布您的viewPager xml吗?
  public class ViewPagerAdapter extends FragmentPagerAdapter {
      private final Context context;

      public ViewPagerAdapter(FragmentManager fragmentManager, Context context) {
          super(fragmentManager);
          this.context = context;
      }
  
      @Override
      public Fragment getItem(int position) {
          if(position == 0) return new ActiveConversationFragment();
          if(position == 1) return new InvitedConversationFragment();
          if(position == 2) return new RecentConversationFragment();

          throw new IllegalStateException("Unexpected position " + position);
      }
  
      @Override
      public int getCount() {
          return 3;
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          if(position == 0) return context.getString(R.string.tab_active_conversation_title);
          if(position == 1) return getString(R.string.tab_invited_conversation_title);
          if(position == 2) return getString(R.string.tab_recent_conversation_title);
        
          throw new IllegalStateException("Unexpected position " + position);
      }
  }
  setupViewPager(viewPager);
    tabLayout.setupWithViewPager(viewPager);
<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:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/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="wrap_content"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorPrimaryDark"
            app:tabTextColor="@color/colorAccent"
            app:tabSelectedTextColor="@color/colorAccent"
            android:id="@+id/tabs">

            <android.support.design.widget.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/tab_np"
                android:text="@string/now_playing"
                android:textColor="@color/colorAccent"/>

            <android.support.design.widget.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/up_coming"
                android:id="@+id/tab_up"/>

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

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

    <include layout="@layout/content_main"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_below="@+id/appbarlayout"
        android:layout_marginTop="1dp"/>

</RelativeLayout>