@Tyhj
        
        2017-04-18T09:14:31.000000Z
        字数 1329
        阅读 4829
    Android
原文:https://www.zybuluo.com/Tyhj/note/726892
RecycleView和NestedScrollView嵌套,有时候会导致页面显示异常,NestedScrollView显示位置不是最顶端,而且和CoordinatorLayout一起会导致CollapsingToolbarLayout里面的内容向上缩进去了一点,反正就是有问题。
让NestedScrollView滑动到顶端这个办法一看就觉得麻烦,解决办法就是先设置RecycleView,首先防止滑动冲突。
第一:RecycleView是固定高度的:
recycleView.setFocusable(false);
第二:RecycleView不是固定高度的:
//先给RecycleView外面嵌套一个RelativeLayoutrecycleView.setFocusable(false);recycleView.setNestedScrollingEnabled(false);
其实第二种很好的方法就是给RecycleView添加头部就好了,添加头部的话其实就是设置viewType就好了。
嵌套一个RelativeLayout这种东西其实我也不是很懂,有时候就会得到意想不到的效果。
ScrollView中嵌套了LinearLayout,LinearLayout中包含了ImageView,可是我始终不能调整ImageView的高度,导致ScrollView太长图片被拉伸,嵌套一个RelativeLayout好了:
<RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:layout_marginLeft="70dp"android:layout_marginRight="70dp"android:gravity="center"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:src="@drawable/home_word_bt3x" /><TextViewandroid:layout_width="match_parent"android:layout_height="50dp"android:gravity="center"android:text=""android:textAppearance="@android:style/TextAppearance.Material.Title"android:textColor="@color/black"android:textSize="16sp" /></RelativeLayout>
