我在3个文件夹中有一个图像res / drawable-hdpi / mdpi / ldpi 600 * 600作为分辨率)我有这个XML文件来显示textview和图像:
<?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 :(得分: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_height
更改为wrap_content
。
另外,还有其他一些事情:
android:layout_below="@id/sipLabel"
,但这仅适用于RelativeLayout。所以这个属性被默默地忽略了。layout_weight
,但0.35
非常随意。由于它是LinearLayout中唯一具有权重的子项,因此它将接收所有额外的垂直空间。 xmlns:android="http://schemas.android.com/apk/res/android"
。答案 1 :(得分:1)
我认为layout_below
仅适用于RelativeLayouts。此外,layout_weight="0.35"
看起来很可疑,我认为这并不意味着你的意思。我认为它必须有一个整数值。
答案 2 :(得分:1)
由于TextView
的高度为fill-parent
,而LinearLayout
未滚动(除非放入ScrollView
,否则无法看到下方部分) ,您的TextView
占据了活动的整个屏幕,其下的ImageView
不可见。
所以你可以
LinearLayout
放入
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>