我有一个包含RecyclerView
的布局和一个用于显示更多项目的布局。当通过点击“显示更多”按钮收到一个或多个项目时,将通知适配器并将项目添加到RecyclerView上。 但问题是,在添加项目后,RecyclerView的高度未展开。
此布局是ViewPager
下CollapsingToolbarLayout
中包含的片段的一部分。
片段布局的结构:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#f5f5f5">
<com.github.rahatarmanahmed.cpv.CircularProgressView
android:id="@+id/progress_view"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
app:cpv_animAutostart="true"
app:cpv_indeterminate="true"
app:cpv_thickness="4dp"/>
<LinearLayout
android:id="@+id/list_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/reviews_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@+id/show_more_container"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#eee">
<TextView
android:id="@+id/show_more_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Show More"
android:textSize="15sp"
android:textColor="@color/colorPrimary"/>
<com.github.rahatarmanahmed.cpv.CircularProgressView
android:id="@+id/show_more_progress_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:visibility="invisible"
app:cpv_animAutostart="true"
app:cpv_indeterminate="true"
app:cpv_thickness="3dp"/>
</FrameLayout>
</LinearLayout>
</FrameLayout>
目前的状态是这样的:
答案 0 :(得分:1)
试试这个
答案 1 :(得分:0)
替换此
<LinearLayout
android:id="@+id/list_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
到
<LinearLayout
android:id="@+id/list_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
同时将Recyclerview高度更改为match_parent
答案 2 :(得分:0)
将您的LinearLayout
更改为RelativeLayout
,将FrameLayout
锚定到底部父级,将RecyclerView
更改为FrameLayout
,如下所示:
<RelativeLayout android:id="@+id/list_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.RecyclerView
android:id="@+id/reviews_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/show_more_container" />
<FrameLayout
android:id="@+id/show_more_container"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#eee">
<TextView
android:id="@+id/show_more_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Show More"
android:textSize="15sp"
android:textColor="@color/colorPrimary"/>
<com.github.rahatarmanahmed.cpv.CircularProgressView
android:id="@+id/show_more_progress_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:visibility="invisible" />
</FrameLayout>
</RelativeLayout>
将RecyclerView
身高改为match_parent
答案 3 :(得分:0)
检查此修改后的布局。 为recyclerview和按钮增加重量会使它固定在特定的位置。希望它适合你。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#f5f5f5">
<com.github.rahatarmanahmed.cpv.CircularProgressView
android:id="@+id/progress_view"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
app:cpv_animAutostart="true"
app:cpv_indeterminate="true"
app:cpv_thickness="4dp"/>
<LinearLayout
android:id="@+id/list_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/reviews_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"/>
<FrameLayout
android:id="@+id/show_more_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:background="#eee">
<TextView
android:id="@+id/show_more_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Show More"
android:textSize="15sp"
android:textColor="@color/colorPrimary"/>
<com.github.rahatarmanahmed.cpv.CircularProgressView
android:id="@+id/show_more_progress_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:visibility="invisible"
app:cpv_animAutostart="true"
app:cpv_indeterminate="true"
app:cpv_thickness="3dp"/>
</FrameLayout>
</LinearLayout>