我有一个显示动态内容的RecyclerView。我会在其他视图之间显示此RecyclerView。例如,一个视图上方和下方RecyclerView显示一个视图中显示:查看上方和下方RecyclerView
View
RecyclerView
View
然而,无论我尝试似乎并没有被工作和RecyclerView似乎占据整个空间。我相信问题在于wrap_content issue,尽管我已经尝试了一些建议的解决方案,例如this custom LinearLayoutManager,但似乎无法解决我的问题。
尝试:
<?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:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- AppBar works fine; no issue here -->
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/app_bar_layout">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_collapseMode="pin"/>
</android.support.design.widget.AppBarLayout>
<!-- Not displaying; Tried different views -->
<com.chrynan.taginput.view.TextInputWrapper
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edit_text_container">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edit_text"/>
</com.chrynan.taginput.view.TextInputWrapper>
<!-- Takes up entire screen space -->
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/swipe_refresh">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recycler_view"/>
</android.support.v4.widget.SwipeRefreshLayout>
<!-- Not displaying -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text_view"/>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
问:有没有办法来放置和上面显示视图和RecyclerView下方查看?如果是这样,怎么样?还是使用ListView更好?
因为我的布局比我给出的例子稍微复杂一些,或者因为使用RecyclerView的已知错误,所以只需添加layout_weight即可。但是,我决定使用ListView而不是RecyclerView,并将layout_weight添加到ListView的确给了我期望的效果。 – chRyNaN
很好的答案。这对我来说工作得很好。 – Mythul
Excellent Super Awesome ...... –