1

我在 3 个文件夹 res/drawable-hdpi/mdpi/ldpi 600*600 中有一个图像作为分辨率),我有这个 XML 文件来显示一个文本视图和图像:

<?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>

有什么问题?感谢您的帮助。

4

3 回答 3

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,因此没有为图像留下空间。尝试更改layout_heightwrap_content.

此外,还有一些其他的事情:

  • 您正在使用android:layout_below="@id/sipLabel",但这仅适用于 RelativeLayout。所以这个属性被默默地忽略了。
  • 虽然您可以选择任何layout_weight您想要的,但0.35非常随意。由于它是 LinearLayout 中唯一具有权重的子元素,因此它将接收所有额外的垂直空间。
  • You don't need to include the xmlns:android="http://schemas.android.com/apk/res/android" on your TextView tag.
于 2011-04-30T19:10:28.990 回答
1

我认为layout_below只适用于RelativeLayouts。另外,这layout_weight="0.35"看起来很可疑,我认为这并不意味着您认为它意味着什么。我认为它必须有一个整数值。

于 2011-04-30T18:51:57.730 回答
1

由于您TextView的高度为fill-parent,并且LinearLayout不滚动(除非放入 aScrollView您看不到下部),因此您TextView占据了 Activity 的整个屏幕,并且ImageView它下面的内容不可见。

所以你可以

  • 将您的整体LinearLayout放入 a ScrollView中,然后向下滚动以查看您的图像,或者
  • 如果您的目标是在屏幕底部显示图像,并且它上方的整个位置都应该是TextView,那么 `RelativeLayout 将是最佳选择。

更新
一个工作RelativeLayout解决方案将是

<?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>
于 2011-04-30T19:09:35.403 回答