Reputation: 505
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
Upvotes: 0
Views: 46
Reputation: 42854
RelativeLayout
will resolve this problemCode:
<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::
You cannot achieve this as a single view
Workaround
Upvotes: 1
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