我們在使用RecyclerView嵌套至ScrollView内的時候
RecyclerView不在螢幕内的資料會不顯示出來,這裡是一個坑,我們需要重寫RecyclerView
/**
* Created by Arcturis lfy on 2019/3/26.
* <p/>
* 解決ScrollView内嵌套引起MyRecyclerView顯示不全的問題
* <p>Copyright</p>
*/
public class MyRecyclerView extends RecyclerView {
public MyRecyclerView(@NonNull Context context) {
super(context);
}
public MyRecyclerView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyRecyclerView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean canScrollVertically(int direction) {
return false;
}
@Override
public boolean canScrollHorizontally(int direction) {
return false;
}
}
即 canScrollVertically 和 canScrollHorizontally這兩個方法傳回為false
而且需要在RecyclerView外層包裹一個RelativeLayout
這樣重新運作下,就能顯示出來了
<ScrollView
android:id="@+id/scrollView_right_up"
android:layout_width="match_parent"
android:scrollbars="none"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<demo.MyRecyclerView
android:id="@+id/recyclerview_right_up"
android:layout_width="match_parent"
android:layout_height="40dp">
</demo.MyRecyclerView>
</RelativeLayout>
</ScrollView>
轉載于:https://www.cnblogs.com/fengfenghuifei/p/10602049.html