Я пытаюсь добавить пользовательский вид в linearlayout, но представление не сохраняет его высоту. Высота 48dp так это фиксируется, но после того, как я addView() это изменится wrap_content:Android - просмотр не поддерживает высоту
LinearLayout cmsList = (LinearLayout) mView.findViewById(R.id.ll_cms_sections);
View group = getActivity().getLayoutInflater().inflate(R.layout.item_cms_group, null);
cmsList.addView(group);
группы:
<?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
android:id="@+id/ll_cms_sections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
I даже попытался заставить его:
group.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 48));
Аргумент высоты должен быть в пикселях не dp. Поэтому try '(int) TypedValue.applyDimension (TypedValue.COMPLEX_UNIT_DIP, 48, context.getResources(). GetDisplayMetrics())' –
Да, вы мужчина! Отредактируйте ответ, я принимаю его! –
Вам не нужно «заставлять» что-либо. Просто передайте родительский 'LinearLayout' в вызов' inflate() '. –