开发者

Problems with Relative layout

I am trying to have an image be at the left, to the right of that, a vertical list (title, address, and date), and to the right of all the url. I can't seem to get the url to display anywhere but on top of the title. Can anyone point me in the right direction?

<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:i开发者_开发知识库d="@+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"
     />

With this current XML attempt with the url to the right of the @id/date...it doesn't appear at all. If I place it toRightOf="@id/icon" it appears literally on top of, not above, the title.

Thanks for any help!


The HeirarchyViewer, under tools, might help you see whats going on. Since you have your layout width set to fill_parent, not wrap_content, its possible that your @id/date doesn't appear because it is being rendered off the screen.

Its hard to tell from your description exactly what you are trying to accomplish, you might add a pic. However, did you try telling the @id/date to align parent left or right?


Please look at the following:

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

Is that what you had in mind? Also I would suggest to consider combination of LinearLayouts (horizontal and vertical).


Here's is the XML that I wrote that makes the layout as I wanted.

<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"
     />

Thank you all for your knowledge!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜