0

I am trying to make an image application and i have a button and and image view in one of my xml files. I have a default picture on the image view. On some devices its to small or its too big. I dont want the picture to go outside the screen or over the button. How would i do this? here is the xml code

<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/btakePic"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:text="Take Picture" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="fill_parent"
    android:layout_height="400dp"
    android:gravity="center"
    android:src="@drawable/android_syh" />

</RelativeLayout>
brian
  • 1
  • 1
  • 1
  • 5
  • Can you post the whole xml file? – 0gravity Jul 13 '12 at 20:47
  • If that's the entire contents of your xml layout file, you have other problems. Where's the parent layout element? – TJ Thind Jul 13 '12 at 20:56
  • You do realize you have drawable-hdpi, drawable-ldip, and drawable-mdpi where you can put the same image in different sizes with the same name. At runtime, android will select which of the three folders to pull that drawable from based on pixel density. Take a look [here](http://developer.android.com/guide/practices/screens_support.html) for more info on it. – skUDA Jul 13 '12 at 21:02

1 Answers1

0

Maybe this is what you want:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/RelativeLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"    
    >

    <Button
        android:id="@+id/btakePic"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="Take Picture" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/btakePic"        
         />

</RelativeLayout>

No need to have android:gravity="center" since you have android:layout_width="fill_parent"

Hope that helps.

0gravity
  • 2,682
  • 4
  • 24
  • 33
  • this kinda helps it doesnt go over the screen or over the button except on the 2.7 inch phones but on the tablets its still to far is there a way to have the picture go right above the take picture button? – brian Jul 13 '12 at 21:00
  • You mean that the picture does not covers the whole screen? is because you set the height to 400dp if you want the picture to be bigger on a tablet then just set the height to fill parent. – 0gravity Jul 13 '12 at 21:02
  • ok i got it... its – brian Jul 13 '12 at 21:07
  • Yea that is what I said on the comment above yours :) Glad that is working like you want it to. – 0gravity Jul 13 '12 at 21:09