Reputation: 1330
I am trying to make a view overlay another view. Here is my XML:
<RelativeLayout
android:background="@android:color/black"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1"
android:id="@+id/test"
android:clipChildren="false"
android:scrollbarStyle="outsideOverlay" >
<RadioGroup
android:id="@+id/radioButtonGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:paddingTop="?android:attr/actionBarSize">
<RadioButton
android:button="@null"
android:checked="true"
android:contentDescription="ZONA"
android:background="@drawable/tab_back_selector"
android:textColor="@color/tab_text_color"
android:textSize="12sp"
android:layout_weight="1"
android:id="@+id/tabZoneHome"
android:padding="14dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/home_tab_zone"
android:gravity="center"/>
<RadioButton
android:button="@null"
android:contentDescription="VISITADAS"
android:background="@drawable/tab_back_selector"
android:textColor="@color/tab_text_color"
android:textSize="12sp"
android:layout_weight="1"
android:id="@+id/tabVisitedHome"
android:padding="14dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/home_tab_visited"
android:gravity="center"
android:checked="false" />
<RadioButton
android:button="@null"
android:contentDescription="SUGERENCIAS"
android:background="@drawable/tab_back_selector"
android:textColor="@color/tab_text_color"
android:textSize="12sp"
android:layout_weight="1"
android:id="@+id/tabSuggestionsHome"
android:padding="14dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/home_tab_suggestions"
android:gravity="center"
android:checked="false" />
</RadioGroup>
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/radioButtonGroup" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="6dp"
android:background="@drawable/quickview_top_gradient"/>
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
I want the RadioGroup to go above the frame_container but so far no luck. I have tried the following in java:
RadioGroup myButton = (RadioGroup) ((Activity) context).findViewById(R.id.radioButtonGroup);
RelativeLayout layout = (RelativeLayout)((Activity)context).findViewById(R.id.test);
layout.bringChildToFront(AdsRecycler.this);
layout.invalidate();
However nothing is changed the. The Radio Group does not overlay the frame_container. What am I doing wrong?
Upvotes: 0
Views: 4639
Reputation: 695
Just move you RadioGroup below FrameLayout in your XML.
<RelativeLayout
android:background="@android:color/black"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1"
android:id="@+id/test"
android:clipChildren="false"
android:scrollbarStyle="outsideOverlay" >
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/radioButtonGroup" />
<RadioGroup
android:id="@+id/radioButtonGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:paddingTop="?android:attr/actionBarSize">
<RadioButton
android:button="@null"
android:checked="true"
android:contentDescription="ZONA"
android:background="@drawable/tab_back_selector"
android:textColor="@color/tab_text_color"
android:textSize="12sp"
android:layout_weight="1"
android:id="@+id/tabZoneHome"
android:padding="14dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/home_tab_zone"
android:gravity="center"/>
<RadioButton
android:button="@null"
android:contentDescription="VISITADAS"
android:background="@drawable/tab_back_selector"
android:textColor="@color/tab_text_color"
android:textSize="12sp"
android:layout_weight="1"
android:id="@+id/tabVisitedHome"
android:padding="14dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/home_tab_visited"
android:gravity="center"
android:checked="false" />
<RadioButton
android:button="@null"
android:contentDescription="SUGERENCIAS"
android:background="@drawable/tab_back_selector"
android:textColor="@color/tab_text_color"
android:textSize="12sp"
android:layout_weight="1"
android:id="@+id/tabSuggestionsHome"
android:padding="14dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/home_tab_suggestions"
android:gravity="center"
android:checked="false" />
</RadioGroup>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="6dp"
android:background="@drawable/quickview_top_gradient"/>
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Upvotes: 1
Reputation: 44118
First, how do you expect the the views to be over one another when you specified:
android:layout_below="@+id/radioButtonGroup"
This will always shift the FrameLayout
below the radio buttons. Remove this line.
Second android lays items in order. So your radio buttons is the base layer then goes the FrameLayout and so on. You want to first put the background (FrameLayout), then the RadioGroup
:
<RelativeLayout>
<FrameLayout/>
<RadioGroup>
...
</RadioGroup>
...
</RelativeLayout>
Upvotes: 3
Reputation: 1131
You are not using frame layout correctly. place radio group and image view as child of the frame layout and you can remove the relative layout which is not required
Upvotes: -1
Reputation: 607
Relative layouts arrange items with respect to the positions of other items and, as far as i know, do not allow overlaying. Use a frame layout instead.
Upvotes: 0