<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ImageView
android:id="#+id/showImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="#string/showImg"
/>
<Button
android:id="#+id/photo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/showImg"
android:text="#string/photo"
/>
</RelativeLayout>
When I run above code image view come over the photo button.
How should I avoid it?
You have two options:
1- Use LinearLayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<ImageView
android:id="#+id/showImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="#string/showImg"
/>
<Button
android:id="#+id/photo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/photo" />
</LinearLayout>
2- Use attribute layout_below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="#+id/showImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="#string/showImg"
/>
<Button
android:id="#+id/photo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/showImg"
android:text="#string/photo"
/>
</RelativeLayout>
I'm assuming you want Image above button. Otherwise you can use layout_above, layout_toLeftOf or layout_toRightOf.
Related
What I am trying to do is wrap the textview around the imageview so that way the text isn't just on the left or right side of the image. Is it possible to do this through XML? As it is a popup dialog with a picture, so doing it through code will be a pain as it is multiple images depending on what they click. See picture for example.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#android:color/background_light">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="1dp"
android:background="#android:color/darker_gray">
>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="20dp">
<Button
android:id="#+id/dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Close" />
<ImageView
android:id="#+id/IV1"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/IV1"
android:layout_below="#+id/dismiss"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/TV15"
android:id="#+id/TV15"
android:layout_below="#+id/dismiss"
android:layout_toRightOf="#+id/IV1"
android:layout_toEndOf="#+id/IV1"
android:paddingLeft="5dp"
android:paddingTop="5dp"/>
</RelativeLayout>
</ScrollView>
</LinearLayout>
Use FrameLayout. Change the order of ImageView and TextView to set what should come top of the other.
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/menu_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/menu_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:lines="1"
android:text="this is my sample" />
</FrameLayout>
I have two image in layout .I want to show second image in bottom edge curve of first image .Can anybody tell how to do like overlay image
Thanks
Use FrameLayout :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imgFirst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"/>
<ImageView
android:id="#+id/imgSecond"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:src="#drawable/ic_launcher"/>
</FrameLayout>
Use a RelativeLayout, simple put the second ImageView below the first ImageView. Then what you have to do is to set the marginTop attribute of the second image to a negative value, and this value is the overlaying size, like this android:layout_marginTop="-1dp".
A sample code right below:
<?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"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/firstImage"
android:src="#drawable/myimage1"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_marginTop="-1dp"
android:layout_height="wrap_content"
android:id="#+id/secondImage"
android:layout_below="#+id/firstImage"
android:src="#drawable/myimage2"
/>
</RelativeLayout>
You can do it without Frames, only using RelativeLayout, if you make use of the alignParentalXXX tags as in the following example
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E4E3CE"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="75">
<ImageView
android:id="#+id/backgroundImageView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:background="#ffffff" />
<ImageView
android:id="#+id/imageView"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:background="#40000000"
android:gravity="center_vertical"
android:paddingHorizontal="3dp"
android:paddingVertical="1dp"
android:text="Header Text"
android:textColor="#ffffff"
android:textSize="16dp" />
</RelativeLayout>
</LinearLayout>
You can see how this layout looks like in the following image:
Use Frame Layout like sample below :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll_home_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#android:color/black"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/ic_drawer"
android:src="#drawable/logo" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="14dp"
android:src="#drawable/menu" />
<ImageView
android:id="#+id/ic_drawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/textView1_detail"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:src="#drawable/ic_drawer" />
<TextView
android:id="#+id/textView1_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/imageView1"
android:text="Reports"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/overlay_favorite"
android:layout_width="215dp"
android:layout_height="134dp"
android:layout_gravity="right"
android:background="#drawable/overlay_favorite"
android:visibility="gone" />
</FrameLayout>
</LinearLayout>
how can i overlap a Button over another inside RelativeLayout ?
Example
Thanks.
Here is what i've tried. Thanks
<RelativeLayout
android:id="#+id/category"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical|center_horizontal|center"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/btn2"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:src="#drawable/btn1" />
<ImageView
android:id="#+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/btn2" />
</RelativeLayout>
You could do it by setting the margin to a negative value.
<?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="wrap_content">
<ImageView android:id="#+id/btn1"
android:layout_width="100dp"
android:layout_height="50dp"/>
<ImageView android:layout_width="100dp"
android:layout_height="50dp"
android:layout_toRightOf="#id/btn1"
android:layout_marginLeft="-20dp"/>
</RelativeLayout>
this is how you can achieve it.
use layout_margin attribute for the button on right and give it a negative value.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/category"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MyLargeBtn" />
<Button
android:id="#+id/btn2"
android:layout_toRightOf="#id/btn1"
android:layout_marginLeft="-10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SmallBtn" />
I have 2 image I want to put one image over another my xml follows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imgThumb"
android:layout_width="60dip"
android:layout_height="80dip"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20sp"
android:src="#drawable/bg" />
<TextView
android:id="#+id/imgText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:ellipsize="marquee"
android:singleLine="true"
android:text="test string"
android:textColor="#000000"
android:textSize="10dip"
android:visibility="gone" />
<View
android:layout_width="fill_parent"
android:layout_height="30sp"
android:background="#drawable/shelf" />
Layout looks like this
I want this first image over this second image.so that it looks like that this first image is standing over second image
Change the LinearLayout to RelativeLayout, switch the places of the 2 images.
<?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" >
<View
android:id="#+id/shelf"
android:layout_below="#+id/imgThumb"
android:layout_width="fill_parent"
android:layout_height="30sp"
android:background="#drawable/shelf" />
<ImageView
android:id="#+id/imgThumb"
android:alignParentTop="true"
android:layout_width="60dip"
android:layout_height="80dip"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20sp"
android:src="#drawable/bg" />
Change Layout Linear to Relative or FramLayout and add Margin Top in views.
In relative layout each and every control Automatically over its above control.
Try below code.
<ImageView
android:id="#+id/imgThumb"
android:layout_width="60dip"
android:layout_height="80dip"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20sp"
android:src="#drawable/abc" />
<TextView
android:id="#+id/imgText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:ellipsize="marquee"
android:singleLine="true"
android:text="test string"
android:textColor="#000000"
android:textSize="10dip"
android:visibility="gone" />
<View
android:layout_width="fill_parent"
android:layout_height="30sp"
android:layout_marginTop="20sp"
android:background="#drawable/ic_launcher" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="138dp"
android:layout_marginTop="142dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView2"
android:layout_alignTop="#+id/imageView2"
android:layout_marginTop="15dp"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
I need to design the UI part in android device is,
Actually I'm having one title bar image and four piece of menu image.
I'm using relative layout for designing this menu. But every time it's having some problem to show the last image in device.
How Can I design this?Please help me.
Your should use below code for achieving it ..
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/btnHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="10dip" />
<Button
android:id="#+id/btnMenu1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btnHeader"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dip" />
<Button
android:id="#+id/btnMenu2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btnMenu1"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dip" />
<Button
android:id="#+id/btnMenu3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btnMenu2"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dip" />
<Button
android:id="#+id/btnMenu4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btnMenu3"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dip" />
</RelativeLayout>
Try with the below code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/image1" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image2"
android:layout_marginTop="10dp"
android:layout_gravity="center"/>
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image3"
android:layout_marginTop="10dp"
android:layout_gravity="center"/>
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image4"
android:layout_marginTop="10dp"
android:layout_gravity="center"/>
</LinearLayout>