我发现RecyclerView
内的RecyclerView
内的GridLayot
上的最后一个项目无法显示。
我尝试删除GridLayot
并仅使用RecyclerView
,它可以显示所有项目,但是我不能使用这些解决方案,因为我也需要显示我的AppBarLayout
。因此,我需要使用GridLayot
来使AppBarLayout
和RecyclerView
成为一个群组,并且SwipeRefreshLayout
才能使用。
我该如何解决,谢谢!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorWhite">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/activity_cost_diamond_history_swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorComtGray">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="1"
android:rowCount="2">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:layout_row="0">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/activity_cost_diamond_history_user_cost_diamond_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:src="@drawable/ic_point" />
<TextView
android:id="@+id/activity_cost_diamond_history_user_cost_diamond_text"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:gravity="center"
android:textColor="@color/colorBlack"
android:textSize="17sp" />
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/activity_cost_diamond_history_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</GridLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout>
答案 0 :(得分:0)
使recyclerview行1
<androidx.recyclerview.widget.RecyclerView
android:layout_row="1"
android:id="@+id/activity_cost_diamond_history_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
或使用您的布局
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/activity_cost_diamond_history_swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="1"
android:rowCount="1">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:layout_row="0">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/activity_cost_diamond_history_user_cost_diamond_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:src="@drawable/ic_back" />
<TextView
android:id="@+id/activity_cost_diamond_history_user_cost_diamond_text"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:gravity="center"
android:textColor="@color/background"
android:textSize="17sp" />
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
</GridLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/activity_cost_diamond_history_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
答案 1 :(得分:0)
尝试此代码。我认为这会对您有所帮助。
<?xml version="1.0" encoding="utf-8"?>
<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"
android:orientation="vertical"
tools:context=".MainActivity">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/activity_cost_diamond_history_swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="1"
android:rowCount="2">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_row="0"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/activity_cost_diamond_history_user_cost_diamond_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:src="@drawable/ic_point" />
<TextView
android:id="@+id/activity_cost_diamond_history_user_cost_diamond_text"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:gravity="center"
android:textColor="@color/colorBlack"
android:textSize="17sp" />
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/activity_cost_diamond_history_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10"
android:layout_marginBottom="@dimen/dp_20"
android:scrollbars="vertical" />
</GridLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>