Я с помощью CoordinatorLayout с AppBarLayout внутри и элемента, чтобы попытаться, чтобы иметь возможность прокрутки при RecyclerView в настоящее время прокручивается. До этого все работает так, как это принято, проблемы возникают, когда я пытаюсь программно прокручиватьToPosition последних позиций RecyclerView. recyclerViews делает прокрутку, но позиция, которую я говорю для прокрутки, не видна (на самом деле, если я прокручиваю ее вручную, она видна, когда другой элемент внутри AppBarLayout полностью прокрутил экран). Это мой код:RecyclerLayout внутри видимости CoordinatorLayout scrollToPosition
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<com.github.mikephil.charting.charts.BarChart
android:id="@+id/chart"
android:layout_width="match_parent"
android:layout_height="280dp"
android:layout_below="@+id/toolbar_conso"
android:background="@color/background_dark_grey"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="@+id/linear_total_conso"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="@+id/current_consumption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/graph_consumption_color"
android:textSize="30sp" />
<TextView
android:id="@+id/consumption_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:text=""
android:textAppearance="@style/TextAppearance.Smartlink.Large"
android:textColor="@color/graph_consumption_color" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
И код RecyclerView:
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
recyclerView.setAdapter(adapter);
Адаптер представляет собой простой текстовый адаптер ........
Когда я попробуйте выполнить прокрутку после получения события из Сервиса, поэтому есть BroadcastReceiver, который принимает событие и управляет результатом:
@Override
public void onReceive(Context context, Intent intent) {
int position = intent.getExtras().getInt(POSITION);
recyclerView.scrollToPosition(position);
}
Моя идея заключается в том, что я думаю, что RecyclerView does't понимает, что позиция не видно .....
Хорошо Телль мне, что вам нужно, recyclerView не должен прокручиваться, если элемент не отображается или вы хотите прокрутить RecyclerView, а также AppbarLayout? –
Я хочу, чтобы RecyclerView прокручивался до положения, которое я хочу (и оно должно быть видимым для реального). Если я удалю CoordinatorLayout и AppBarLayout, он работает так, как я хочу, проблема в том, что RecyclerView прокручивается до «невидимой» (вне видимости пользователя) позиции, когда я выполняю scrollToPosition для последних элементов списка ... .. – zapotec