我使用正常的recyclerview
并设置为LinearLayoutManager.HORIZONTAL
,现在当我单击按钮recyclerview
时应展开为垂直,如果再次单击该按钮,则应重新设置为水平{再次{1}}。
recylerview
onButtonClick
<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" />
条件始终为0 如何动态更改 谢谢
答案 0 :(得分:0)
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;
}