2010-08-06 99 views
1

我想要在左边,右边的一个垂直列表(标题,地址和日期),以及所有网址的右侧。我似乎无法让网址显示在标题顶部的任何地方。任何人都可以将我指向正确的方向吗?相对布局的问题

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="?android:attr/listPreferredItemHeight" 

android:padding="6dip"> 

<ImageView 
    android:id="@+id/icon" 

    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 

    android:layout_alignParentTop="true" 
    android:layout_alignParentBottom="true" 
    android:layout_marginRight="6dip" 
/> 

<TextView 
    android:id="@+id/title" 

    android:layout_width="fill_parent" 
    android:layout_height="20dip" 

    android:layout_toRightOf="@id/icon" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentRight="true" 
    android:textStyle="bold" 
    android:singleLine="true" 
    android:ellipsize="marquee" 
/> 

<TextView 
    android:id="@+id/address" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textSize="12dip" 
    android:layout_toRightOf="@id/icon" 
    android:layout_alignParentRight="true" 
    android:layout_below="@id/title" 
/> 
<TextView 
    android:id="@+id/date" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@id/icon" 
    android:layout_below="@id/address" 
    android:layout_alignParentRight="true" 
    android:textSize="12dip" 
    android:singleLine="true" 
    android:ellipsize="end" /> 
<TextView 
    android:id="@+id/url" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@id/date" 
    /> 

用的URL @ ID /日期右边这个电流XML的尝试......它不会出现在所有。如果我将它放置到RightOf =“@ id/icon”,它就会出现在字幕上方,而不是字幕上方。

感谢您的帮助!

回答

0

下面是我写的使我按照需要布局的XML。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="?android:attr/listPreferredItemHeight" 

android:padding="6dip"> 

<ImageView 
    android:id="@+id/icon" 

    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 

    android:layout_alignParentTop="true" 
    android:layout_alignParentBottom="true" 
    android:layout_marginRight="6dip" 
/> 

<TextView 
    android:id="@+id/title" 

    android:layout_width="fill_parent" 
    android:layout_height="20dip" 

    android:layout_toRightOf="@id/icon" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentRight="true" 
    android:textStyle="bold" 
    android:singleLine="true" 
    android:ellipsize="marquee" 
/> 

<TextView 
    android:id="@+id/address" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textSize="12dip" 
    android:layout_toRightOf="@id/icon" 
    android:layout_alignParentRight="true" 
    android:layout_below="@id/title" 
/> 
<TextView 
    android:id="@+id/date" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@id/icon" 
    android:layout_below="@id/address" 
    android:textSize="12dip" 
    android:singleLine="true" 
    android:ellipsize="end" /> 
<TextView 
    android:id="@+id/url" 
    android:layout_marginLeft="10dip" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@id/date" 
    android:layout_alignBaseline="@id/date" 
    android:autoLink="web" 
    android:textColorLink="#7d26cd" 
    /> 

谢谢大家对你的知识!

0

工具下的HeirarchyViewer可能会帮助您了解正在发生的事情。由于您的布局宽度设置为fill_parent,而不是wrap_content,因此它可能不会显示您的@ id/date,因为它正在屏幕上显示。

很难从描述中确切地告诉你想要完成什么,你可以添加一张图片。但是,您是否尝试告诉@ id/date将父对象左对齐或右对齐?

0

请看以下内容:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="wrap_content" android:layout_width="fill_parent"> 
<ImageView android:id="@+id/ImageView01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/icon"> 
</ImageView> 
<TextView android:layout_height="wrap_content" 
    android:text="@+id/title" 
    android:layout_width="wrap_content" 
    android:layout_toRightOf="@+id/ImageView01" 
    android:id="@+id/title"> 
</TextView> 
<TextView android:layout_below="@+id/title" 
    android:layout_height="wrap_content" 
    android:text="@+id/address" 
    android:id="@+id/address" 
    android:layout_toRightOf="@+id/ImageView01" 
    android:layout_width="wrap_content"> 
</TextView> 
<TextView android:layout_below="@+id/address" 
    android:layout_height="wrap_content" 
    android:text="@+id/date" 
    android:id="@+id/date" 
    android:layout_toRightOf="@+id/ImageView01" 
    android:layout_width="wrap_content"> 
</TextView> 
<TextView android:layout_below="@+id/title" 
    android:layout_height="wrap_content" 
    android:text="@+id/url" 
    android:id="@+id/url" 
    android:layout_toRightOf="@+id/address" 
    android:layout_width="fill_parent"> 
</TextView> 

</RelativeLayout> 

是你脑子里想的是什么?此外,我会建议考虑LinearLayouts(水平和垂直)的组合。

+0

我确实弄清楚了我的问题......这是我在日期元素中有“fill_parent”。由于优化,我也试图远离LinearLayouts。在这个URL(http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html)它声称“这种布局的工作(LinearLayout),但可以浪费如果你实例化它ListView的每个列表项目,可以使用单个RelativeLayout重写相同的布局,从而节省一个视图,甚至更好地在视图层次结构中的每个列表项目的一个级别。“ – taraloca 2010-08-07 11:49:56

+0

我的意思是告诉你,我试过你的XML,它也可以工作!谢谢! – taraloca 2010-08-07 12:07:29

+0

好帖子!感谢您指出。 – Asahi 2010-08-07 12:23:31