我无法理解我做错了什么。我的内部有一个ScrollView
和RecyclerView
。我知道在Android中禁用双滚动。我动态地禁用了RecyclerView
上的滚动。之后,ScrollView的滚动必须正常工作。但事实并非如此。
MainActivity
public class MainActivity extends AppCompatActivity {
private RecyclerView lvParents;
ParentsAdapter adapter_parents;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lvParents = (RecyclerView)findViewById(R.id.lvParents);
fillListParents();
}
public void fillListParents(){
ArrayList listParents = new ArrayList();
int j = 0;
for (j = 0; j < 6; j++){
ParentsAdapterObject parObj = new ParentsAdapterObject(
"pinfo_id",
"pinfo_title",
"pinfo_date",
"pinfo_text");
listParents.add(parObj);
Log.d("rklogs", "j_" + j);
}
adapter_parents = new ParentsAdapter(listParents, this);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this) {
@Override
public boolean canScrollVertically() {
return false;
}
};
lvParents.setLayoutManager(linearLayoutManager);
lvParents.setAdapter(adapter_parents);
}
ParentsAdapter
public class ParentsAdapter extends RecyclerView.Adapter<ParentsAdapter.PersonViewHolder>{
public static Context ctx;
ParentsAdapterObject pd;
ArrayList<ParentsAdapterObject> listParents;
public ParentsAdapter(ArrayList<ParentsAdapterObject> listParents, Context ctx){
this.listParents = listParents;
this.ctx= ctx;
}
@Override
public PersonViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_parents_adapter,
viewGroup, false);
PersonViewHolder pvh = new PersonViewHolder(v);
return pvh;
}
@Override
public void onBindViewHolder(PersonViewHolder personViewHolder, int i) {
pd = listParents.get(i);
personViewHolder.tvTitle.setText(pd.getTitle());
personViewHolder.pdo = pd;
}
@Override
public int getItemCount() {
return listParents.size();
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
public static class PersonViewHolder extends RecyclerView.ViewHolder {
TextView tvTitle;
ParentsAdapterObject pdo;
PersonViewHolder(View itemView) {
super(itemView);
tvTitle = (TextView)itemView.findViewById(R.id.tvTitle);
tvTitle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("rklogs", tvTitle.getText().toString());
Log.d("rklogs", pdo.getTitle());
}
});
}
}
}
ParentsAdapterObject
public class ParentsAdapterObject {
public String title;
public String text;
public String date;
public String id;
public ParentsAdapterObject(String id, String title, String date, String text){
this.title = title;
this.date = date;
this.text = text;
this.id = id;
}
public String getTitle(){
return title;
}
public String getText(){
return text;
}
public String getId(){
return id;
}
public String getDate(){
return date;
}
}
main_activity
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="row.balinasoft.by.testfucknigscroll.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView"
android:background="#251100ff"
android:fillViewport="true">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lvParents"
android:visibility="visible"/>
</ScrollView>
答案 0 :(得分:0)
而不是ScrollView
使用NestedScrollView
setNestedScrollingEnabled(false)
对象上和RecyclerView
NestedScrollView
能够处理(启用/禁用)内部滚动
答案 1 :(得分:0)
如上所述禁用在回收站视图对象上滚动后,您可以检查以下使用嵌套滚动视图而不是普通滚动视图的代码段。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!-- your other view's/view-group's go here-->
</LinearLayout>