Android图像位置

时间:2013-12-02 14:20:33

标签: android image layout position

我有问题。有了这张图片,我可以更好地解释。

image http://oi40.tinypic.com/5evixf.jpg

为此,我使用此.xml文件:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.5"
    android:background="#ff0000"
    >

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:src="@drawable/img_black" />            

</RelativeLayout>
<View
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.5"
    android:background="#00ff00"
    />
 </LinearLayout>

我想把黑色矩形放在底部,以便消除黑色矩形下的红线,然而,这仍然是绿色的。显然黑色矩形是一个图像,而其余部分只是背景颜色,只是为了清楚地表明我会将图像(黑色矩形)尽可能地放在屏幕的一半。

1 个答案:

答案 0 :(得分:0)

ImageView中的

尝试使用android:background="@drawable/img_black"代替android:src,如下所示:

      <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:background="@drawable/img_black" 
        android:layout_marginTop = "20dp"/>