2017-12-15 1 views
1

동적 목록과 마지막 항목 아래에 정적 선형 레이아웃이 있습니다. 목록이 비어 있으면 LinearLayout이 페이지 상단에 있습니다.Dynamic RecyclerView 아래의 LinearLayout 목록보기

목록에 요소를 추가 할 때마다 LinearLayout이 목록의 마지막 항목 아래로 이동합니다. 목록이 길어지면 고정 LinearLayout은 화면 끝 부분에 있어야합니다. 나는 더 나은 이해를 위해 몇 가지 예를 그린다.

enter image description here

그러나 필자는 7 요소를 추가 할 때마다, 내 선형 레이아웃 목록 아래에 숨어있다.

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    <android.support.v7.widget.RecyclerView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="@dimen/app_margin" 
     android:id="@+id/group_manage_list_view" 
     android:paddingBottom="40dp" 
     /> 

     <LinearLayout 

      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_below="@+id/group_manage_list_view" 
      > 

      <Button 
       android:layout_width="34dp" 
       android:layout_height="34dp" 
       android:background="@drawable/ic_add_circle_outline_white_24dp" 
       android:layout_gravity="center_vertical" 
       android:layout_marginLeft="@dimen/app_margin" 
       android:backgroundTint="@color/headline_grey" 
       android:id="@+id/create_group_button_click"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/add_group" 
       android:layout_marginLeft="@dimen/app_margin" 
       android:layout_gravity="center_vertical" 
       /> 


     </LinearLayout> 

    </RelativeLayout> 

답변

1

당신이 이것을 달성하기 위해 android:layout_weight를 사용할 수 있지만 당신은 유지해야 당신의 recycleview 그 아래 linearlayout의는, 배열 크기가 다른 표시되지 반대의 경우도 마찬가지

수 있도록보다 큰 0보다 경우라고 가시성
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/group_manage_list_view" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1.8" 
     android:padding="10dp" 
     android:paddingBottom="40dp" 
     android:visibility="gone" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.2" 
     android:minHeight="50dp" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/create_group_button_click" 
      android:layout_width="34dp" 
      android:layout_height="34dp" 
      android:layout_gravity="top" 
      android:layout_marginLeft="10dp" 
      android:background="@drawable/ic_launcher_background" 
      android:backgroundTint="@color/colorAccent" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top" 
      android:layout_marginLeft="10dp" 
      android:text="add_group" /> 

    </LinearLayout> 

</LinearLayout> 
+0

흠 나는이 예가 목록에 2 개의 항목을 가지고있을 때이 방법이 효과가 있습니까? 목록 크기를 확인하고 listView를 볼 때 화면에 1.8 공간이 필요하고 선형 레이아웃이 화면 하단에 표시됩니까? – Expiredmind

+0

예, 만료되었습니다. 목록에 데이터가있는 경우 화면에 표시되며 선형 레이아웃은 아래쪽에 표시됩니다. 선형 레이아웃은 표시되지 않고 문제가 해결됩니다. –

+0

@Expiredmind는 귀하의 문제가 해결되지 않았습니까? –

1

NestedScrollView 여기에 샘플 코드가 필요하다고 생각합니다. 이것이 당신을 도울 수 있기를 바랍니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

<android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

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

     <LinearLayout 

      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Seomthing" /> 
     </LinearLayout> 
    </LinearLayout> 
</android.support.v4.widget.NestedScrollView> 
</LinearLayout> 

이렇게하면 내 대답을 upvote하십시오. 해피 코딩 ..

+0

이 접근법은 거의 효과적입니다. 선형 레이아웃은 목록이 커지면 숨기지 않지만 안타깝게도 항상 화면에 표시되지는 않습니다 (예를 들어 7 개의 항목이 있으면 선형 레이아웃을 보려면 아래로 스크롤해야합니다) – Expiredmind

+0

'nestedScrollView'를 제거한 다음 'RecyclerView' 높이를 만듭니다 'match_parent'를 실행하고'layout_weight = 1'을 부여합니다. –

+0

'RecyclerView'에서'layout_weight = 1'은 화면 하단에 항상'LinearLayout'을 만듭니다 – Expiredmind

관련 문제