当我将RecyclerView放在嵌套的scrollview中时,屏幕总是跳到RecyclerView的顶部而不是页面的顶部.这是一个简单的例子.
layout xml:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="350dp"
android:background="@android:color/holo_blue_dark"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</layout>
Run Code Online (Sandbox Code Playgroud)
虚拟适配器的活动:
public class RecycleViewTestActivity extends AppCompatActivity {
public static class ExampleAdapter extends RecyclerView.Adapter<ExampleViewHolder> {
private Context context;
public ExampleAdapter(Context context) {
this.context = context;
}
@Override
public ExampleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
TextView view = new TextView(context);
view.setText("Test");
return new ExampleViewHolder(view);
}
@Override
public void onBindViewHolder(ExampleViewHolder holder, int position) {
} …Run Code Online (Sandbox Code Playgroud) 在一个视图分页器中,我有几个片段,其中一个片段使用带有标题和recyclerview的嵌套scrollview:
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.m360.android.fragment.Members.MemberDetailsFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="20dp">
<header/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingTop="0dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
标签"header"代表了一个复杂的布局,我不想在这里发布,因为它会大量延伸代码.
当我在标签之间切换时,它会将海峡滚动到回收站视图.标题是隐藏的,我必须向上滚动才能看到它.
关于是什么原因的任何想法?如果可以避免,我不想在我的适配器中使用类型.
我有一个父回收站视图,里面有3个子视图.孩子的最后两个是recyclerview.
Parent recyclerview
- child view 1
- child view 2 (horizontal rv)
- child view 3 (horizontal rv)
Run Code Online (Sandbox Code Playgroud)
问题是每当这个片段可见时,它会自动滚动以与child view 2底部对齐.
我已将父rv设置为侦听滚动.这就是我最终的结果:
dy: 108
dy: 72
dy: 75
dy: 62
dy: 48
dy: 42
dy: 34
dy: 27
dy: 22
dy: 16
dy: 12
dy: 10
dy: 7
dy: 5
dy: 3
dy: 3
dy: 1
dy: 1
dy: 1
Run Code Online (Sandbox Code Playgroud)
这似乎是起始dy父recyclerview被设定为0在child view 2RV.它上面的一切都是-ve值.但是,我不确定是否是这种情况,因为我仍然在找出导致它的原因.
任何修复?
我有一个包含ImageView和RecyclerView的Scrollview.如果导航抽屉打开然后关闭RecyclerView自动滚动到顶部,如何停止此操作?
<RelativeLayout 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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollViewMain"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView_main_icons_line"
android:src="@drawable/main_line" />
...
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView_activity_main_passenger_log"
android:paddingBottom="2dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)