I have a FrameLayout which contains 2 views , the second is something like a Close Button (X)
and i want to position it on the right.
I've tried layout_gravity = " right ", but that didn't work.
This is my layout xml :
<FrameLayout android:layout_width="320dp"
android:layout_height="wrap_content"
android:id="@+id/layoutSmallImg">
<ImageView android:id="@+id/bigImage"
android:layout_width="320dp" android:layout_height="wrap_content"/>
<ImageView android:id="@+id/bigImage"
android:layout_width="320dp" android:layout_height="wrap_content"/>
<ImageButton android:id="@+id/closebutton"
android:background="@android:color/transparent"
android:layout_height="30dp" android:layout_marginTop="10dp"
android:layout_alignParentRight="true"
android:layout_width="30dp" android:paddingLeft="40dp"
android:visibility="gone"
android:src="@drawable/close" />
</FrameLayout>
Read the DOCS:
Try:
You can place a view in 9 different places within a FrameLayout
Enjoy
Do you want to use FrameLayout or RelativeLayout?
My understanding says that FrameLayout is used if you want to replace your current view with another view. Your requirement can be fulfilled by RelativeLayout.
Use a RelativeLayout instead.
Just put your elements inside FrameLayout to the second RelativeLayout. And use android:layout_alignParentRight="true" for the element which you want to align right.
I recommend you to use a
RelativeLayout
insteadBTW, do you want the button on top of the ImageView or next to it? You're setting the width of both the layout and the imageView to the same size.
After the comment, I can see two options:
android:paddingLeft="250dp"
make the button size 320dp and add a custom background, mostly transparent. Make it patch 9 so you can determine where to add the text in it (see my answer here for how to do that: How to create android spinner without down triangle on the right side of the widget)
Programatically, you can set the margin using FrameLayout.LayoutParams. The following would work to place a view on the bottom of your screen: