RecyclerView:为什么超出屏幕右边缘的景观元素?

时间:2015-02-03 18:20:24

标签: android android-layout android-recyclerview recycler-adapter

使用RecyclerView时出现问题。当您将方向更改为横向时,我将列数= 2.但右列在屏幕外显示。我不知道可以像这个Holder那样创建什么问题

        @Override
        public ViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType)
        {
            final View view = inflater.inflate(R.layout.item, parent, false);
            return new ViewHolder(view);
        }

项目布局

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
......
</FrameLayout>

RecyclerView init

recyclerView.setHasFixedSize(true);
    layoutManager = new StaggeredGridLayoutManager(getColumnCount(),  StaggeredGridLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    adapter.setSelectionListener(this);
    recyclerView.setAdapter(adapter);     

enter image description here

UPD

<android.support.v4.widget.SwipeRefreshLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swipe_refresh_layout"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
    <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            />
</android.support.v4.widget.SwipeRefreshLayout>

1 个答案:

答案 0 :(得分:0)

我认为您应该将此命令添加到AppTheme

<item name="android:windowTranslucentNavigation">false</item>