2012-12-16 84 views
0

我使用这个布局:安卓:ImageView的不显示

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linearLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:textColor="#372c24" /> 

    <View 
     android:id="@+id/space" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="5" 
     android:background="@android:color/transparent" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="4" 
     android:orientation="horizontal" 
     android:background="@drawable/shape_popup"> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" /> 
     <ImageView 
      android:contentDescription="@string/app_name" 
      android:id="@+id/rateStar" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:background="@drawable/image" /> 
    </LinearLayout> 

</LinearLayout> 

但不显示图像,为什么呢?

+2

尝试使用属性:android:src =“@ drawable/image” –

+0

@Matt Clark:它的工作原理,谢谢:) –

+0

不是问题!快乐编码! :) < - 我稍微解释了一个答案:p –

回答

1

ImageBiew不会显示任何东西,直到它会得到一些源,以便使用该

android:src="@drawable/image" 

还修改TextView的宽度并不需要它,你是给一个权重。

  <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" /> 
0

你应该使用Android:SRC,而不是机器人:背景是这样的:

<ImageView 
     android:contentDescription="@string/app_name" 
     android:id="@+id/rateStar" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:src="@drawable/image" /> 

编辑:由于您使用的是重量属性layout_width以0: 你也应该设置机器人

 <ImageView 
     android:contentDescription="@string/app_name" 
     android:id="@+id/rateStar" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:src="@drawable/image" /> 
1

当您使用属性:

android:background="" 

它通常会寻找类似颜色的东西,例如#FFFF0000 < - 红色,并且它不会在容器中填充图像。

要获得的图像与正确的安装容器,你需要使用属性:android:src="@drawable/..."

有了这个,你也可以使用android:scaleType="..."

对容器内的更换不同规模类型的图像。

+0

在'background'属性上设置'drawable'没有问题,Android仅仅在'ImageView'上略微不同地处理'background'和'src'。 – Rawkode