как расширить горизонтальный Recyclerview в вертикальный - PullRequest
0 голосов
/ 04 мая 2020

Я использую обычный recyclerview и устанавливаю LinearLayoutManager.HORIZONTAL, теперь, когда я нажимаю кнопку, recyclerview должно расширяться до вертикального, и если я снова нажимаю на кнопку, он снова должен вернуться в горизонтальное recylerview.

  <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:orientation="horizontal"
            android:layout_marginTop="10dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/topCategoryTxt" />

onButtonClick

if (LinearLayoutManager.HORIZONTAL == 0) {
                    layoutManager = new LinearLayoutManager(HomeScreen.this, LinearLayoutManager.VERTICAL, false);
                    recyclerview.setLayoutManager(layoutManager);
                    recyclerview.setAdapter(popularItemsAdapter);
                    adapter.notifyDataSetChanged();
                }else{
          layoutManager = new LinearLayoutManager(HomeScreen.this, LinearLayoutManager.HORIZONTAL, false);
                    recyclerview.setLayoutManager(layoutManager);
                    recyclerview.setAdapter(popularItemsAdapter);
                    adapter.notifyDataSetChanged();
}

Состояние всегда равно 0 как изменить его динамически Спасибо

1 Ответ

0 голосов
/ 04 мая 2020
boolean orientaion = false

if (!orientaion) {
                layoutManager = new LinearLayoutManager(HomeScreen.this, LinearLayoutManager.VERTICAL, false);
                recyclerview.setLayoutManager(layoutManager);
                recyclerview.setAdapter(popularItemsAdapter);
                adapter.notifyDataSetChanged();
                orientaion=true;
            }else{
      layoutManager = new LinearLayoutManager(HomeScreen.this, LinearLayoutManager.HORIZONTAL, false);
                recyclerview.setLayoutManager(layoutManager);
                recyclerview.setAdapter(popularItemsAdapter);
                adapter.notifyDataSetChanged();
                orientaion=false;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...