RelativeLayout between two view
-
Objective:
RelativeLayout.
There's a header with a fixed height, relativeLayout, attached to the top of the element's mouth with the help of
android:layout_alignParentTop="true"
There's a footer with a fixed height, attached to the bottom of the element with help.
android:layout_alignParentBottom="true"
There's a RelativeLayout, which several TextView, HorizontalScrollView, LinearLayout.
I need this RelativeLayout(content) located between header's and footer's.
In doing so, the components inside RelativeLayout(content) need to be compressed/extensive, depending on the free space, and complete the whole medium part of the rut-element.
RelativeLayout(content) shall have three horizontal scrubs in which the ImageView will be dynamically added.
Like I'm trying to realize:
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>
That's how ImageView is added in 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); }
Issues:
- How do we achieve the desired result? To cover the pictures Did you decrease/increase and fit between heder and futer?
- Maybe I don't have the right approach in general?
Thank you for your help!
-
Because you have all the elements going underneath others,
- instead
RelativeLaout
Better useLinearLayout
candroid:orientation="vertical"
- So you won't even need an internal "content"
RelativeLaout
Use. - In order for the elements in the middle to take all the available heights, they need to be given equal weight to each other, and the height of wound zero. So they'll take the whole height equally apart from the height occupied by elements with specified heights.
The marking shall therefore be approximately:
<LinearLayout 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" android:orientation="vertical>
<TextView android:id="@+id/tv1" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="0dip" android:text="Some Text 111"/> <HorizontalScrollView android:id="@+id/hs1" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="0dip"> <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_weight="1" android:layout_height="0dip" android:text="Some Text 222"/> <HorizontalScrollView android:id="@+id/hs2" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="0dip"> <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_weight="1" android:layout_height="0dip" android:text="Some Text 333"/> <HorizontalScrollView android:id="@+id/hs3" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="0dip"> <LinearLayout android:id="@+id/ll3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > </LinearLayout> </HorizontalScrollView> <LinearLayout android:id="@+id/footer" android:layout_width="match_parent" android:layout_height="ЗАДАЙТЕ_КОНКРЕТНОЕ ЗНАЧЕНИЕ ТУТ" android:orientation="horizontal"> </LinearLayout>
</LinearLayout>
- instead