I had a TitleBar(#lotTopTitleBar) in the LinearLayout, and the LinearLayout will be full size of the screen, now, I want show a View(#lotFloatView) reference the TitleBar below, but both view aren't at the same level container, so the layout_below doesn't work, if anybody know about that, please help me a change.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout android:id="@+id/lotTopTitleBar"
android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
</LinearLayout>
<LinearLayout android:id="@+id/lotFloatView"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_below="@id/lotTopTitleBar">
<Button android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@null" />
<Button android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@null" />
</LinearLayout>
</RelativeLayout>
RelativeLayout lets child views specify their position relative to the parent view or to each other (specified by ID). So you can align two elements by right border, or make one below another, centered in the screen, centered left, and so on.
Following attributes can be used for doing so. Suppose there is one view in the center and its id is given as android:id="@+id/main" Therefore, the other new views can be placed relative to this view as following: This tells the new view that you have to be on the left side of the view whose id is main.
To set an element like TextView below another TextView in RelativeLayout in android app is easy to do with layout xml. You can do it like this. in the above code welcome TextView will come after heading. Now we will do it programatically.
In a RelativeLayout you can keep (position) the new views relative to other existing views. Following attributes can be used for doing so. Suppose there is one view in the center and its id is given as android:id="@+id/main" Therefore, the other new views can be placed relative to this view as following:
I think you can achieve this by using relative layout instead of linear layout. I have not tested it but it should work.
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout android:id="@+id/lotTopTitleBar"
android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
<LinearLayout android:id="@+id/lotFloatView"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_below="@id/lotTopTitleBar">
<Button android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@null" />
<Button android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@null" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@id/lotTopTitleBar"
android:id="@+id/lotLL"
android:layout_weight="1">
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_below="@id/lotLL"
android:layout_height="50dp">
</LinearLayout>
</RelativeLayout >
EDIT
<LinearLayout android:layout_width="match_parent"
android:layout_below="@id/lotLL"
android:layout_alignParentBottom="true"
android:id="@+id/lotLastLL"
android:layout_height="50dp">
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/lotTopTitleBar"
android:layout_above="@id/lotLastLL"
android:id="@+id/lotLL"
>
</LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With