2017-01-07 1 views
1

implementingRecylerView이어야하며 항목 내용 높이가 적은 경우 내용을 래핑해야합니다. 항목이 증가한 경우 250dp과 같이 최대 heght(250dp)으로 설정해야하며 스크롤 할 수 있어야합니다.이 상위 레이아웃을 달성하는 방법은 Relative layout입니다.RecyclerView의 최대 높이를 설정하는 방법은 무엇입니까?

의 하나 item.This가 wrap_content 할 필요가있는 경우이 내 레이아웃 파일

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.RecyclerView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/recycler_view" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:layout_alignParentBottom="true" 
     android:layout_gravity="bottom" /> 

</RelativeLayout> 

스크린 샷입니다. RecylerView

Screen Shot if its only one item.This should be wrap_content.

+0

사용'ScrollView' . – AlphaQ

+0

@AlphaQ'ScrollView' 대신 'RelativeLayout' 또는 현재의'ScrollView' 내부의 'Relative layout' –

+3

Google에서 maxHeight를 제거하는 이유는 무엇입니까? 정말 불편합니다. –

답변

3

당신이 programetically 설정할 수 있습니다 높이의 경우 부모 레이아웃과 같은 하나의 항목 만 ... 다른 wrap content

ViewGroup.LayoutParams params=recycler_view.getLayoutParams(); 
params.height= RecyclerView.LayoutParams.WRAP_CONTENT; 
recycler_view.setLayoutParams(params); 

<dimen name="view_height">250dp</dimen> 

float height= getResources().getDimension(R.dimen.view_height); //get height 

ViewGroup.LayoutParams params_new=recycler_view.getLayoutParams(); 
params_new.height=height; 
recycler_view.setLayoutParams(params_new); 
관련 문제