图片走出手机屏幕

时间:2012-07-13 20:43:46

标签: android xml camera image sizing

我正在尝试创建一个图像应用程序,并且在我的一个xml文件中有一个按钮和图像视图。我在图像视图上有一个默认图片。在某些设备上它很小或太大。我不希望图片出现在屏幕外或按钮上。我该怎么办? 这是xml代码

<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>

1 个答案:

答案 0 :(得分:0)

也许这就是你想要的:

<?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>

由于您拥有android:gravity="center"

,因此无需android:layout_width="fill_parent"

希望有所帮助。