我正在为回收者视图寻找相当于addHeaderView的东西.基本上我想要一个带有2个按钮的图像作为标题添加到列表视图中.是否有不同的方法将标题视图添加到回收站视图?指导的一个例子会很有帮助
编辑2(添加片段布局):
添加日志语句后,似乎getViewType只接收到0的位置.这导致onCreateView只加载一个布局:
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766 5449-5449/co.testapp I/logger info? …Run Code Online (Sandbox Code Playgroud) 当我将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) 我有一个父回收站视图,里面有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值.但是,我不确定是否是这种情况,因为我仍然在找出导致它的原因.
任何修复?
我有一个ViewPager作为线性布局中的项目,视图寻呼机中的每个项目都包含一个RecyclerView.问题是,无论何时页面最初加载,或者我在ViewPager上更改页面,视图都会自动滚动,因此回收器视图的开头是屏幕的顶部,而不是保持原样.
这个问题的.gif就在这里.注意我没有向下滚动,这是自动重新定位.
如何防止视图自动重新定位到回收器视图的开头?