2016-10-13 1 views
0

선형보기에 사용자 정의보기를 추가하려고하는데보기가 그 높이를 유지하지 않습니다. 이 고정 그래서 높이 48dp하지만 난이) addView를 (할 후에는 wrap_content로 변경안드로이드 -보기가 높이를 유지하지 않습니다

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

I

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="48dp" 
android:background="@color/clear_orange"> 

<com.dekibae.android.popinthecity.presentation.ui.widgets.FontText 
    android:id="@+id/tv_cms" 
    style="@style/TitleOrangexNormal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginEnd="@dimen/margin_normal" 
    android:layout_marginStart="@dimen/margin_normal" 
    android:layout_toLeftOf="@+id/indicator" 
    android:gravity="center" 
    android:paddingTop="4dp" 
    android:text="TEST SECTION" 
    app:font="@string/plaak" /> 

<ImageView 
    android:id="@+id/indicator" 
    android:layout_width="24dp" 
    android:layout_height="24dp" 
    android:layout_alignParentEnd="true" 
    android:layout_centerVertical="true" 
    android:layout_marginEnd="@dimen/margin_normal" 
    android:scaleType="centerInside" 
    android:src="@drawable/dropdown_arrow" /> 

</RelativeLayout> 

cmsList을 :

LinearLayout cmsList = (LinearLayout) mView.findViewById(R.id.ll_cms_sections); 

View group = getActivity().getLayoutInflater().inflate(R.layout.item_cms_group, null); 

cmsList.addView(group); 

그룹 심지어 강제로 시도 :

@Abtin Gramian의 의견에 따기 (210)는
group.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 48)); 
+2

높이 인수는 dp가 아닌 픽셀 단위 여야합니다. 그래서'(int) TypedValue.applyDimension (TypedValue.COMPLEX_UNIT_DIP, 48, context.getResources(). getDisplayMetrics())' –

+0

예, 당신은 남자입니다! 답변을 수락합니다. 수락합니다. –

+0

"강제로"할 필요가 없습니다. 'inflate()'호출에서 부모 LinearLayout 만 전달하십시오. –

답변