相对布局,ImageView 位于右侧,图像左侧有 3 个文本视图,一个在下一个
我正在尝试使用relativelayout 在左侧显示一张图像,并在图像右侧显示 3 个文本视图,一个在另一个下面。类似的解释如下:http://android-developers。 blogspot.com/2009/02/android-layout-tricks-1.html。我遇到的问题是第三个文本视图不显示。
我的代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="2dip">
<ImageView android:layout_width="96dip"
android:layout_height="96dip" android:layout_alignParentTop="true"
android:layout_alignParentBottom="true" android:layout_marginRight="2dip"
android:id="@+id/myIcon" android:src="@drawable/icon" />
<TextView android:id="@+id/Line1" android:layout_width="fill_parent"
android:layout_height="30dip" android:layout_toRightOf="@id/myIcon"
android:layout_alignParentRight="true" android:text="Line 1" />
<TextView android:layout_width="fill_parent"
android:layout_height="30dip" android:layout_toRightOf="@id/myIcon"
android:layout_below="@id/Line1"
android:text="Line 2" android:id="@+id/Line2" />
<TextView android:layout_width="fill_parent"
android:layout_height="30dip" android:layout_toRightOf="@id/myIcon"
android:layout_below="@id/Line2"
android:id="@+id/Line3" android:text="Line 3" />
</RelativeLayout>
这可能是一些非常简单或明显的事情,我要么做错了,要么忘记做,但我真的可以用一双新的眼睛看一眼。 谢谢!
I'm trying to use a RelativeLayout to display an image on the left side, and 3 text views, one below another, to the right of the image. Similar is explained here: http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html. The problem I'm having is that the 3rd text view does not display.
My code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="2dip">
<ImageView android:layout_width="96dip"
android:layout_height="96dip" android:layout_alignParentTop="true"
android:layout_alignParentBottom="true" android:layout_marginRight="2dip"
android:id="@+id/myIcon" android:src="@drawable/icon" />
<TextView android:id="@+id/Line1" android:layout_width="fill_parent"
android:layout_height="30dip" android:layout_toRightOf="@id/myIcon"
android:layout_alignParentRight="true" android:text="Line 1" />
<TextView android:layout_width="fill_parent"
android:layout_height="30dip" android:layout_toRightOf="@id/myIcon"
android:layout_below="@id/Line1"
android:text="Line 2" android:id="@+id/Line2" />
<TextView android:layout_width="fill_parent"
android:layout_height="30dip" android:layout_toRightOf="@id/myIcon"
android:layout_below="@id/Line2"
android:id="@+id/Line3" android:text="Line 3" />
</RelativeLayout>
It's probably something really simple or obvious that I'm either doing wrong or forgetting to do, but I could really use a fresh pair of eyes taking a glance at this.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试添加
到您的 Line1 TextView。我不确定这是否能解决您的问题,但这是值得尝试的事情。
另外,关于 ID 的“+”号:这些用于您的 ID 声明。因此,在所有元素中,您都会有这样的内容:
这就是您所拥有的。但是,您不需要将它们用于参考目的。所以
是正确的。将“+”视为声明一个 ID,并且为了引用它,您不需要它。
另外:尝试在视图后面放置一些背景颜色,以确保它们按照您期望的方式显示。这是我经常使用的调试技巧。
Try adding
to your Line1 TextView. I'm not sure if this will fix your issue, but it's something to try.
Also, in regard to the '+' sign for IDs: These are for your id declarations. So, in all of your elements, you would have something like this:
Which is what you have. However, you do not need them for reference purposes. So
would be correct. Think of the '+' as declaring an ID and for referencing it, you do not need it.
Also: Try placing some background colors behind your views to make sure they are showing up how you expect them to. That's a debug tip that I use constantly.