Цель:
Рут элемент в разметке - RelativeLayout.
Есть header(допустим RelativeLayout) с фиксированной высотой, который прижат к верху рут элемента с помощью
android:layout_alignParentTop="true"
Есть footer(допустим LinearLayout) с фиксированной высотой, который прижат к низу рут элемента с помощью
android:layout_alignParentBottom="true"
Есть RelativeLayout(обозвем его content), в котором есть несколько TextView, HorizontalScrollView, LinearLayout.
Мне нужно, чтобы этот RelativeLayout(content) размещался между header'ом и footer'ом.
При этом нужно чтобы компоненты внутри RelativeLayout(content) сжимались/расширялись в зависимости от свободного пространства и заполняли всю среднюю часть рут-элемента.
В RelativeLayout(content) должны быть три горизонтальных скролла, в которые динамически добавятся ImageView.
Как я сейчас пытаюсь реализовать:
activity_main.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:fitsSystemWindows="true"
tools:context=".MainActivity"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="@dimen/header_layout_height"
android:layout_alignParentTop="true">
</RelativeLayout>
<RelativeLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/footer"
android:layout_below="@+id/header">
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Some Text 111"/>
<HorizontalScrollView
android:id="@+id/hs1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv1">
<LinearLayout
android:id="@+id/ll1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/hs1"
android:text="Some Text 222"/>
<HorizontalScrollView
android:id="@+id/hs2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv2">
<LinearLayout
android:id="@+id/ll2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
<TextView
android:id="@+id/tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/hs2"
android:text="Some Text 333"/>
<HorizontalScrollView
android:id="@+id/hs3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv3">
<LinearLayout
android:id="@+id/ll3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
<LinearLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
</LinearLayout>
</RelativeLayout>
Вот так добавляю ImageView в LinearLayout:
LinearLayout layout1 = (LinearLayout) findViewById(R.id.ll1);
for (int i = 0; i < 10; i++) {
ImageView imageView = new ImageView(this);
imageView.setId(i);
imageView.setPadding(0, 0, 8, 0);
imageView.setImageBitmap(BitmapFactory.decodeResource(
getResources(), R.drawable.cow));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
layout1.addView(imageView);
}
Вопросы:
- Как добиться желаемого результата ? Чтобы скролл с картинками уменьшался/увеличивался и вписывался между хедером и футером ?
- Возможно у меня не правильный подход в целом ?
Спасибо за помощь!