RecyclerView的wrap_content在CoordinatorLayout中不起作用

时间:2016-08-08 00:44:44

标签: android-layout android-recyclerview

我正在尝试制作wrap_content RecyclerView,但它不起作用。

我写这个xml代码:

    <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"
android:fitsSystemWindows="true"
tools:context="br.com.moviee.activity.ItemActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:background="@android:color/transparent"
    android:fitsSystemWindows="true"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleMarginEnd="64dp"
        app:titleEnabled="true"
        android:fitsSystemWindows="true">

        <com.facebook.drawee.view.SimpleDraweeView
            android:transitionName="@string/transition_poster"
            android:id="@+id/poster"
            android:layout_width="match_parent"
            android:layout_height="400dp"
            android:scaleType="centerCrop"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax"/>

        <View
            android:id="@+id/collapsing_comp"
            android:layout_gravity="bottom"
            android:layout_width="match_parent"
            android:layout_height="140dp" />

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_collapseMode="pin"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

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

<android.support.v4.widget.NestedScrollView
    android:id="@+id/scroll"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

<include layout="@layout/content_item" />
</android.support.v4.widget.NestedScrollView>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_anchor="@id/app_bar_layout"
    app:layout_anchorGravity="bottom|right|end"
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@android:drawable/ic_dialog_email" /></android.support.design.widget.CoordinatorLayout>

我的RecyclerView项目xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">


<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/thumb_trailer"
    android:scaleType="centerCrop"
    android:layout_margin="1dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<ImageView
    android:layout_gravity="center"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/ic_play_arrow"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" /></RelativeLayout>

内容布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_item"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="wrap_content"
tools:context="br.com.moviee.activity.ItemActivity"
tools:showIn="@layout/activity_item">

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

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

    <TextView
        android:background="@android:color/white"
        android:textStyle="bold"
        android:textSize="14sp"
        android:padding="16dp"
        android:text="@string/title_trailer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <android.support.v7.widget.RecyclerView
        android:background="@android:color/white"
        android:id="@+id/grid_trailer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" /></LinearLayout>

并编写此java代码:

private void configGrid() {
    if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
        layoutManager = new GridLayoutManager(this, Youtube.COLUM_NUMBER_PORTRAIT);
    else
        layoutManager = new GridLayoutManager(this, Youtube.COLUM_NUMBER_LANDSCAPE);

    trailerGrid.setLayoutManager(layoutManager);
    TrailerGridAdapter adapter = new TrailerGridAdapter(this);
    trailerGrid.setAdapter(adapter);
    trailerGrid.setHasFixedSize(true);
    trailerGrid.setNestedScrollingEnabled(false);
}

我不知道为什么我的Wrap_content RecyclerView不起作用。

0 个答案:

没有答案