2013-12-13 98 views
0

我试图给一个图像视图边框,使用布局来包裹它并将边框设置为该特定布局的背景。然而,图像视图看起来很小,并且在框架背景的左上角。带边框的图像,显​​示不正确

这里是我的代码:

<RelativeLayout 
    android:id="@+id/Relative1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="25dp" 
    android:layout_marginTop="40dp" 
    android:background="@drawable/pic_frame_big_01" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" /> 
</RelativeLayout> 

使图像适合相对布局并占有它我怎么能修改此代码。

编辑更改了ImageView的代码,现在图像居中,但它看起来像是一个以父级为中心的非常小的图像。

<ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" /> 
+0

将一些图像设置为'src'到图像视图。现在它是空的! –

回答

0

因为您将其设置为左上对齐。删除它们并更改宽度和高度以匹配。试试这个:

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

编辑:您的相对布局也对准左上角。尝试删除对齐属性。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/Relative1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginTop="40dp" 
    android:background="@drawable/border_red" > 

    <ImageView 
     android:src="@drawable/holotaglogo" 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true"/> 
</RelativeLayout> 
+0

错误,这使得我的相对布局占据了所有空间。整个页面 – User3

0

尝试增加:android:padding="10dp"RelativeLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/Relative1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="25dp" 
    android:layout_marginTop="40dp" 
    android:background="@drawable/pic_frame_big_01" 
    android:padding="10dp"> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:src="@drawable/image1" /> 
</RelativeLayout> 

android:src="@drawable/image1也很重要..,你在你的项目中的一些图像代替image1

+0

已更新的问题,现在我把它设置在中心,但只有一个小图片显示 – User3

+0

看到我的评论..我把这个在我的答案也..设置'android:src =“”'某些图像。 。 –