2011-04-30 43 views
1

我在3个文件夹RES图像/可绘-HDPI/MDPI/LDPI 600 * 600的分辨率)和i具有此XML文件以显示一个TextView和图像:图像在UI未示出

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/sipLabel" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    /> 
    <ImageView android:id="@+id/connected" android:src="@drawable/connected" android:layout_below="@id/sipLabel" 
    android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_weight="0.35" android:gravity="center" 
     /> 
     </LinearLayout> 

有什么可以解决这个问题? 谢谢你的帮助。

+0

你看到了什么问题? – Jordan 2011-04-30 18:50:36

+0

@Jordan:图像不显示。任何想法 ?谢谢。 – androniennn 2011-04-30 18:59:40

+0

我相信这是在你的TextView的layout_height属性上设置的'fill_parent'标签。有关更多详情,请参阅下面的答案。 – Jordan 2011-04-30 19:20:38

回答

2

的主要问题是在LinearLayout你的第一个标签:

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/sipLabel" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    /> 

由于layout_height设置为fill_parent这个TextView的垂直填充LinearLayout,离开g没有图像的空间。尝试将layout_height更改为wrap_content

此外,一对夫妇的其他东西:

  • 您使用android:layout_below="@id/sipLabel",但在RelativeLayout的这只作品。所以这个属性被默默地忽略了。
  • 虽然你可以选择任何layout_weight你想要的,0.35是相当随意的。由于它是LinearLayout中唯一具有重量的孩子,因此它将获得所有额外的垂直空间。
  • 您不需要在TextView标签上包含xmlns:android="http://schemas.android.com/apk/res/android"
+0

我刚刚将layout_height更改为wrap_content,现在它正在工作。非常感谢你。 XML文件非常非常敏感:(。 – androniennn 2011-04-30 19:25:10

1

我认为layout_below只适用于RelativeLayouts。另外,那layout_weight="0.35"看起来强烈怀疑,我不认为这意味着你的想法。我认为它必须有一个整数值。

+0

我编辑XMl通过删除layout_weight =“0.35”,同样的问题,然后我测试了另一次删除layout_below,同样的问题!任何其他想法?谢谢。 – androniennn 2011-04-30 19:01:09

1

由于您的TextViewfill-parent的高度,而LinearLayout不滚动(除非被放入ScrollView你看不到下部),您TextView占用活动的整个屏幕,并ImageView在它下面是不可见的。

所以你可以

  • 把你的整个LinearLayoutScrollView,和向下滚动查看 你的形象,或
  • 如果你的目标是在 的底部来显示图像屏幕上,并应该采取 整个地方 是TextView,然后 `RelativeLayout将是最好的 选项。

更新
工作RelativeLayout soulution将

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <TextView android:id="@+id/sipLabel" android:text="@string/loremipsum1" 
     android:layout_width="fill_parent" android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" /> 
    <ImageView android:id="@+id/connected" android:src="@drawable/connected" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:layout_below="@id/sipLabel" android:layout_alignParentBottom="true" /> 
</RelativeLayout> 
+0

所以我切换到RelativeLayout而不是LinearLayout =>相同的问题。然后我只是加了一个也是同样的问题!我有没有改变图像分辨率?它现在是600x600:\ – androniennn 2011-04-30 19:14:47

+1

这是因为您仍然将textview设置为填充其父项。 – rekaszeru 2011-04-30 19:34:52