1

In my project I have a menu. for design of menu i want to use gridView. for simplicity assume that this grid view has just one item. This item has two seperate images (background.png and news.png) and a text (for example "NEWS").

Is it possible to map news.png on background.png through xml or code?

Thanks for helping me.

Hesam
  • 52,260
  • 74
  • 224
  • 365

1 Answers1

1

Yes you can always do that using FrameLayout in xml file,Like this.

<FrameLayout android:id="@+id/frameLayout1"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <ImageView android:id="@+id/imageView1" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:src="@drawable/background"></ImageView>
    <ImageView android:id="@+id/imageView2" android:layout_width="wrap_content"
        android:layout_gravity="center" android:layout_height="wrap_content"
        android:src="@drawable/news"></ImageView>
    <TextView android:text="NEWS" android:id="@+id/textView1" android:layout_gravity="bottom|center_horizontal"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</FrameLayout>
MKJParekh
  • 34,073
  • 11
  • 87
  • 98
  • Or you could just set android:background property of parent layout (but it will stretch to layout size). – Sver Feb 29 '12 at 05:52
  • @Sver you mean to say take layout set background and take imageview and textview in that linear layout?..yeh that can work..might not look good programming but can achieve same outcome. – MKJParekh Feb 29 '12 at 05:57
  • well, if background image is just simple background image without much details.. why not? In case of FrameLayout you need to take in account the sizes of images. – Sver Feb 29 '12 at 06:01
  • @MKJParekh I am using above code but When I get size of framelayout is return as the screen size , how to resolve it ? – PriyankaChauhan Nov 03 '16 at 05:58