Reputation: 11632
I have the following layout structure:
I need to align the second LinearLayout to bottom in way that if any part on view inside of the second LinearLayout became visible, the second layout should be resized to be still visible.
How can i do that in the right way please?
Many thanks for any advice.
Upvotes: 0
Views: 5131
Reputation: 1577
Use gravity attributes like
<LinearLayout
android:width="match_parent"
android:height="match_parent"
android:layout_gravity:"bottom">
Upvotes: 1
Reputation: 3269
Use attribute layout_gravity to align any view inside a FrameLayout
<LinearLayout ...
android:layout_gravity:"bottom"
/>
But if you are trying to place it at the bottom of some other layout. Then use relative layout instead.
Example
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_alignParentTop="true"
android:background="@android:color/holo_red_dark"
android:gravity="center"
android:text="some text view"
android:textColor="#fff"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/text"
android:background="#123123"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_alignParentTop="true"
android:background="@android:color/darker_gray"
android:gravity="center"
android:text="some text view at top inside "
android:textColor="#fff"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_alignParentTop="true"
android:background="@android:color/holo_blue_bright"
android:gravity="center"
android:text="some text view at second position "
android:textColor="#fff"
android:textStyle="bold"/>
</LinearLayout>
</RelativeLayout>
For your question "the second layout should be resized to be still visible."
It is better to use RelativeLayout.
Assuming your second LinearLayout is at the bottom of the RelativeLayout.
If it has no child view, it will be invisible if its height is set to wrap_content
. And whenever you add some views to it. It shall resize-itself.
Upvotes: 2