0

I'm struggling to make an image match the borders of the screen. It's a 9 patch image. I've already asked the question (Android: Handling images size for multiple screens) but the answers I had are not satsfying at all so I'll try asking a more general question

If I want to set different layouts according to my screen width, I create a folder for large xlarge small and normal. But how could I preview the layout in the right screen? Eclips preview are several but as it said

xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp

I don't have the same results for 2 "normal screens" 480*854 or 480*800 so how could I proceed? I just want an image to match the layout's border I don't think it's that complicated, is it?

Community
  • 1
  • 1
morg
  • 1,173
  • 4
  • 18
  • 36

1 Answers1

1

In your XML file try

<RelativeLayout 
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/border_layout"
android:background="@drawable/border"
android:orientation="vertical" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     android:layout_alignParentLeft="true"
     android:layout_alignParentRight="true"
    android:src="@drawable/icon1_1" />

</RelativeLayout>

These two parameters will help you align the layout .

       android:layout_alignParentLeft="true"
       android:layout_alignParentRight="true"

If your border is not the parent layout then replace above attributes with these .

         android:layout_alignLeft="@id/border"
         android:layout_alignRight="@id/border"
Jan
  • 859
  • 7
  • 30
  • I do not have background for my relative layout so I put nothing at android background. It does not workm the image still doesn t stretch – morg Feb 07 '13 at 14:12
  • Then what is kind of views of your borders . Just add these two attributes android:layout_alignLeft="@id/border" android:layout_alignRight="@id/border" and remove alignParent layouts – Jan Feb 07 '13 at 14:23
  • by borders I mean limit of the screens – morg Feb 07 '13 at 14:25
  • then use android:layout_width="fill_parent" – Jan Feb 07 '13 at 14:31
  • I answered a same question here http://stackoverflow.com/questions/14747489/android-handling-images-size-for-multiple-screens Since you did not give your code so see above question . Use Weights in linear layout and above code is also a solution . You might not getting my point – Jan Feb 07 '13 at 14:37
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/24135/discussion-between-janshairkhan-and-morg) – Jan Feb 07 '13 at 14:45
  • My problem wat that I used a 9 patch image, while a normal image put in all the folders (ldpi mdpi xhdpi) was enough! Thanks a lot Janshair! – morg Feb 07 '13 at 16:12
  • Thanks. If it does help then accept this as correct answer as encouragement – Jan Feb 07 '13 at 18:06