phongtran phongtran - 10 days ago 9
Android Question

RecycleView does not scroll to the last items

I have a List View with Vertical Scroll, its item contains RecyclerView which will scroll Horizontally.
But when i scroll horizontal, RecyclerView does not allow me to scroll to the last item in the list (the picture below). What's happened with it? Even, i forced it scroll to the last item by setting linearLayoutManager.setStackFromEnd(true); it still does not work, only scroll to half of the 8th item, not the last item in list of 10

Edit: add codes:

list.xml

<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.phongponix.trackingbodybuilding.MainActivity$PlaceholderFragment">

<ListView android:id="@+id/lvExerciseList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="50dp"
></ListView>
</RelativeLayout>


list_item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="20dp">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/imgExcercisePhoto"
android:layout_width="100dp"
android:layout_height="100dp" />

<TextView android:text="aaa"
android:id="@+id/tvExerciseName"
android:layout_width="100dp"
android:layout_height="wrap_content" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvExcerciseRecords"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:layout_margin="10dp"
android:paddingRight="50dp"
android:scrollbars="horizontal">
</android.support.v7.widget.RecyclerView>
</TableRow>
</TableLayout>
</LinearLayout>


list_item_horizontal.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="100dp"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingRight="10dp">
<TextView
android:id="@+id/tvTemp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>


Code for List Adapter:

public View getView(int i, View convertView, ViewGroup viewGroup) {
View view = convertView;
if (convertView == null) {
view = inflater.inflate(R.layout.list_item, null);
viewHolder = new ViewHolder();
viewHolder.title = (TextView) view.findViewById(R.id.tvExerciseName);
view.setTag(viewHolder);
recyclerView = (RecyclerView)view.findViewById(R.id.rvExcerciseRecords);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false);
linearLayoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(trackingPlanHorizontalAdapter);
recyclerView.setNestedScrollingEnabled(false);

} else {
viewHolder = (ViewHolder) view.getTag();
}

if (data.size() > 0) {
ExerciseModel exercise = (ExerciseModel) data.get(i);
viewHolder.title.setText(exercise.getTitle());
} else {
viewHolder.title.setText("No data");
}

return view;
}


Code for Recycle Adapter:

public TrackingPlanHorizontalViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_horizontal, parent, false);
return new TrackingPlanHorizontalViewHolder(itemView);
}

@Override
public void onBindViewHolder(TrackingPlanHorizontalViewHolder holder, int position) {
holder.textView.setText(horizontalList.get(position));

}


enter image description here

Answer

Yes i found your problem,there is problem regarding your list_item.xml change your list item with below code,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="20dp">

    <LinearLayout
        android:id="@+id/first_panel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:src="@mipmap/ic_launcher"
            android:id="@+id/imgExcercisePhoto"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <TextView
            android:id="@+id/tvExerciseName"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:text="aaa" />
    </LinearLayout>
    <android.support.v7.widget.RecyclerView
        android:layout_toRightOf="@+id/first_panel"
        android:id="@+id/rvExcerciseRecords"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </android.support.v7.widget.RecyclerView>
</RelativeLayout>