图像未显示在 UI 中
我在 3 个文件夹 res/drawable-hdpi/mdpi/ldpi 600*600 中有一个图像(分辨率为 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>
可能会出现什么问题? 感谢您的帮助。
I have an image in the 3 folders res/drawable-hdpi/mdpi/ldpi 600*600 as resolution) and i have this XML file to show a textview and the image:
<?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>
What could br the problem?
Thank you for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
主要问题是您在
LinearLayout
中的第一个标签:由于
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"
。The main issue is your first tag in the
LinearLayout
:Since
layout_height
is set tofill_parent
this TextView is filling the LinearLayout vertically, leaving no room for the image. Try changinglayout_height
towrap_content
.Also, a couple of other things:
android:layout_below="@id/sipLabel"
, but this only works in a RelativeLayout. So this attribute is being silently ignored.layout_weight
you want,0.35
is pretty arbitrary. Since it's the only child in the LinearLayout with weight, it will receive all of the extra vertical space.xmlns:android="http://schemas.android.com/apk/res/android"
on your TextView tag.我认为
layout_below
仅适用于RelativeLayouts。另外,layout_weight="0.35"
看起来很可疑,我不认为这意味着你认为的意思。我认为它必须有一个整数值。I think
layout_below
only applies for RelativeLayouts. Also, thatlayout_weight="0.35"
looks mighty suspect, I don't think it means what you think it means. I think it must have an integer value.由于您的
TextView
的高度为fill-parent
,并且LinearLayout
不会滚动(除非放入ScrollView
code> 你看不到下面的部分),你的TextView
占据了 Activity 的整个屏幕,而它下面的ImageView
是不可见的。因此,您可以
LinearLayout
放入ScrollView
,向下滚动查看您的图像,或者
屏幕底部,以及
上面的整个地方都应该被占据
是
TextView
,然后是`RelativeLayout 将是最好的
选项。
更新
一个可行的
RelativeLayout
解决方案是Since your
TextView
has a height offill-parent
, and theLinearLayout
is not scrolling (unless is put into aScrollView
you can't see the lower parts), yourTextView
takes up the whole screen of the Activity, and theImageView
being under it is not visible.So you can either
LinearLayout
into aScrollView
, and scroll down to seeyour image, or
the bottom of the screen, and the
whole place above it should be taken
be the
TextView
, then a`RelativeLayout would be the best
option.
Update
a working
RelativeLayout
soulution would be