2016-05-17 3 views
0

Ich kann nicht verstehen, was ich falsch mache. Ich hatte eine ScrollView und RecyclerView drin. Ich weiß, dass Double Scroll in Android deaktiviert ist. Ich habe scroll auf RecyclerView dynamisch deaktiviert. Und danach muss ScrollViews Bildlauf funktionieren. Aber es ist nicht.Warum ScrollView Scroll funktioniert nicht (wenn RecycleView innerhalb mit deaktivierter Scroll)

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> 

Antwort

0

Statt ScrollView Verwendung NestedScrollView

und setNestedScrollingEnabled(false) auf RecyclerView Objekt

NestedScrollView hat die Fähigkeit, (aktivieren/deaktivieren) inneres Scrolling

+0

Vielen Dank für Ihre Antwort, N J. Aber es doest mir helfen :( –

0

Nachdem Sie auf dem Recycler View Objekt zu behandeln deaktivieren Scrollen wie Sie bereits erwähnt, können Sie die unten Schnipsel überprüfen, die eher eine verschachtelte Scroll-Ansicht verwendet als eine normale Ansicht blättern.

<?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> 

+0

Vielen Dank für Ihre Antwort, niranjian_b. Aber es doest mir helfen :( –