0

我正在尝试制作一个图像应用程序,并且我的一个 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>
4

1 回答 1

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"

希望有帮助。

于 2012-07-13T20:54:53.920 回答