我有一个Recyclerview填充了用户插入的项目.我正在实现旋转的功能,因为当我转动设备时,recyclerview显示为空.
调试应用程序,我已经检查旋转之前和之前的完整性,并且ArrayList具有相同的大小.我认为问题是Recyclerview的setNestedScrollingEnabled(false),我设置了这个,因为我不想在rv中显示滚动.
问题是:我处于纵向模式,我添加了3个项目,它在recyclerview中显示我很完美.检查图像:
当我将屏幕旋转到横向时,recyclerview的arraylist有3个项目,但高度不会改变,所以它只有一个项目.
那么,我如何解决这个问题?
Recyclerview:
itemsRv = (RecyclerView) findViewById(R.id.itemsRv);
itemsRv.setNestedScrollingEnabled(false);
itemAutoCompleteAdapter = new ItemAutoCompleteAdapter(this);
if(items ==null){
items = new ArrayList<>();
}
itemsAdapter = new ItemsRowAdapter(this, items, new ItemsRowAdapter.itemsRowListener() {
@Override
public void editarItemOnClick(View v, int position) {
editar_item(items.get(position), position);
}
@Override
public void eliminarItemOnClick(View v, final int position) {
}
});
itemsRv.setHasFixedSize(true);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
itemsRv.setLayoutManager(mLayoutManager);
itemsRv.setAdapter(itemsAdapter);
布局:
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginBottom="4dp"
android:text="Items"
android:textSize="16sp"
android:textStyle="bold" />
android:id="@+id/header_rv_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4">
android:id="@+id/textView3"
android:layout_width="@dimen/widthColumnTable"
android:layout_height="wrap_content"
android:layout_weight="2.8"
android:textStyle="bold"
android:text="Descripción" />
android:id="@+id/textView5"
android:layout_width="@dimen/widthColumnTable"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="right"
android:textStyle="bold"
android:text="Cantidad" />
android:id="@+id/textView8"
android:layout_width="@dimen/widthColumnTable"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:gravity="right"
android:textStyle="bold"
android:text="Precio total" />
android:text="Acciones"
android:textStyle="bold"
android:layout_width="100dp"
android:gravity="right"
android:layout_height="wrap_content"
/>
android:id="@+id/itemsRv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
android:id="@+id/btn_01_agregar_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="20dp"
android:background="@drawable/border_spinner"
android:gravity="left|center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="Ingrese el código o descrpción del producto"
android:textAllCaps="false"
android:textColor="#616161" />
我试图将android:layout_height更改为wrap_content和match_parent但没有成功.
非常感谢你!