Daniel Raja Singh
Daniel Raja Singh

Reputation: 505

How to achieve the following

How to achive the below image 1. background yellow. 2. selection image on right top. 3. other image on middle 4. text may be above or below based on need

How to achieve this by button or textview or view

image

Upvotes: 0

Views: 46

Answers (2)

Devrath
Devrath

Reputation: 42854

RelativeLayout will resolve this problem


Code:

<RelativeLayout
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_gravity="center"
    android:background="#000000" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView1"
        android:layout_centerHorizontal="true"
        android:text="Text" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>


Snapshot::

enter image description here


{EDIT}

You cannot achieve this as a single view

Workaround

  • You can achieve this as single view using a background drawable
  • Make a background image having both the images in an another image
  • Set that final image as a background for a button
  • You can even use selectors for the button to give a corner background

Upvotes: 1

Antoine Marques
Antoine Marques

Reputation: 1389

Use RelativeLayout. The code will somehow look like this :

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <!-- First image -->
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" />        
    <!-- Second image -->
    <ImageView
        android:id="@+id/mySecondImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/mySecondImage" />
</RelativeLayout

Upvotes: 1

Related Questions