tags:

views:

50

answers:

3

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

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!

A: 

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?

Mayra
A: 

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).

Asahi
I did end up figuring out my problem...it was that I has "fill_parent" in the date element. I was also trying to stay away from the LinearLayouts due to optimazation. At this url (http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html) it claims that "This layout works (LinearLayout) but can be waste ful if you instantiate it for every list item of a ListView. The same layout can be rewritten using a single RelativeLayout, thus saving one view, and even better one level in view hierarchy, per list item."
taraloca
I meant to tell you that I tried your XML and it works too! Thanks!
taraloca
Good post! Thanks for pointing out.
Asahi
A: 

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!

taraloca