2017-02-02 2 views
5

사용자가 삽입 한 항목이있는 Recyclerview가 있습니다. 회전 기능을 구현하고 있는데, 기기를 돌릴 때 recyclerview는 비어있는 것으로 표시됩니다.화면 회전 후 Recyclerview의 크기가 조절되지 않음

응용 프로그램을 디버깅하기 전에 회전 및 ArrayList가 같은 크기를 갖기 전과 그 전에 무결성을 확인했습니다. 문제는 Recyclerview의 setNestedScrollingEnabled(false)이라고 생각합니다. rv에 스크롤을 표시하고 싶지 않기 때문에 이것을 설정했습니다.

문제는입니다. 세로 모드로 3 개 항목을 추가하면 recyclerview에서 완벽하게 표시됩니다. 이미지 확인 : 내가 가로로 화면을 회전 할 때

Portrait

을의 recyclerview의 ArrayList를이 세 항목이 있지만 높이 때문에 변경되지 않습니다 그것은 단지 하나의 항목을 가지고 apppears. 그래서

enter image description here

, 나는이 문제를 어떻게 해결?

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); 

레이아웃 : 내가 성공하지 wrap_contentmatch_parentandroid:layout_height을 변경하려고했습니다

<android.support.v7.widget.CardView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="8dp"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:padding="8dp"> 

       <android.support.v7.widget.AppCompatTextView 
        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" /> 

       <LinearLayout 
        android:id="@+id/header_rv_items" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" 
        android:visibility="visible"> 

        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:orientation="horizontal" 
         android:weightSum="4"> 

         <TextView 
          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" /> 

         <TextView 
          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" /> 

         <TextView 
          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" /> 
         <TextView 
          android:text="Acciones" 
          android:textStyle="bold" 
          android:layout_width="100dp" 
          android:gravity="right" 
          android:layout_height="wrap_content" 
          /> 


        </LinearLayout> 


       </LinearLayout> 

       <android.support.v7.widget.RecyclerView <----- HERE IT IS 
        android:id="@+id/itemsRv" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        /> 


       <Button 
        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" /> 


      </LinearLayout> 
     </android.support.v7.widget.CardView> 

.

대단히 감사합니다!

답변

3

나는 해결책을 찾았습니다. 나는이

itemsRv.setHasFixedSize(true); 
LinearLayoutManager mLayoutManager = new LinearLayoutManager(this); 

itemsRv.setLayoutManager(mLayoutManager); 
RelativeLayout.LayoutParams lp = 
       new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); //<--- ADD 
itemsRv.setLayoutParams(lp);//<--- ADD 
itemsRv.setAdapter(itemsAdapter); 

추가 그리고 내가 https://stackoverflow.com/a/34543165/3200714

에서 생각이있어, 완벽하게 작동

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content"> 
    <android.support.v7.widget.RecyclerView 
    android:id="@+id/itemsRv" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 
</RelativeLayout> 

코드에서 :

내가 이런 RelativeLayout의 내부 Recyclerview를 넣어
관련 문제