[关闭]
@Tyhj 2017-04-18T09:14:31.000000Z 字数 1329 阅读 3905

RecycleView和NestedScrollView嵌套导致页面显示异常和跳动

Android


原文:https://www.zybuluo.com/Tyhj/note/726892

RecycleView和NestedScrollView嵌套,有时候会导致页面显示异常,NestedScrollView显示位置不是最顶端,而且和CoordinatorLayout一起会导致CollapsingToolbarLayout里面的内容向上缩进去了一点,反正就是有问题。

让NestedScrollView滑动到顶端这个办法一看就觉得麻烦,解决办法就是先设置RecycleView,首先防止滑动冲突。

第一:RecycleView是固定高度的:

  1. recycleView.setFocusable(false);

第二:RecycleView不是固定高度的:

  1. //先给RecycleView外面嵌套一个RelativeLayout
  2. recycleView.setFocusable(false);
  3. recycleView.setNestedScrollingEnabled(false);

其实第二种很好的方法就是给RecycleView添加头部就好了,添加头部的话其实就是设置viewType就好了。

嵌套一个RelativeLayout这种东西其实我也不是很懂,有时候就会得到意想不到的效果。

ScrollView中嵌套了LinearLayout,LinearLayout中包含了ImageView,可是我始终不能调整ImageView的高度,导致ScrollView太长图片被拉伸,嵌套一个RelativeLayout好了:

  1. <RelativeLayout
  2. android:layout_width="match_parent"
  3. android:layout_height="wrap_content"
  4. android:layout_gravity="center_horizontal"
  5. android:layout_marginLeft="70dp"
  6. android:layout_marginRight="70dp"
  7. android:gravity="center">
  8. <ImageView
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. android:layout_centerInParent="true"
  12. android:src="@drawable/home_word_bt3x" />
  13. <TextView
  14. android:layout_width="match_parent"
  15. android:layout_height="50dp"
  16. android:gravity="center"
  17. android:text=""
  18. android:textAppearance="@android:style/TextAppearance.Material.Title"
  19. android:textColor="@color/black"
  20. android:textSize="16sp" />
  21. </RelativeLayout>
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注