tags:

views:

42

answers:

3

Hi there. I have a list view and I have to design a row layout to be used in adapter. The layout is like this.

First column we have an icon on left most side. 
Second column we have a string of about 4-30 characters 
Last column, the date with time. 

I tried to design in relative layout but it gave issues like the last two columns' strings were overlapped. I want to specify certain percentage of width to a column, if string doesn't fit, it must start in new line (same row, with gravity as center). This is row layout, so I dont want it to be very heavy. And I dont want to hard code the width in dp. Please help. Thanks.

+1  A: 

Try this layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <ImageView
        android:src="@drawable/image"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" />    
    <TextView  
        android:text="Lorem ipsum dolor sit amet, consectetuer adipiscing elit"
        android:gravity="center_horizontal"
        android:layout_weight="1.0"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" />
    <TextView
        android:text="23.10.2010 23:34:52"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>
Sergey Glotov
Perfect. After making some more changes to layout_weight, I was able to achieve what I wanted. Thanks.
Prabhat
Since Sameer was closer, I will mark his answer as correct. However, I will give +1rep. Thanks.
Prabhat
A: 

Hi

try using TableLayout http://android-pro.blogspot.com/2010/02/table-layout.html

Mina Samy
A: 

Building on Sergey's code (which I believe will not solve the problem completely). I have specified ratios 1/2:1/1:1/3 (for the image:string:date);

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
    <ImageView
        android:src="@drawable/image"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:layout_weight="2" />    
    <TextView  
        android:text="Lorem ipsum dolor sit amet, consectetuer adipiscing elit"
        android:gravity="center_horizontal"
        android:layout_weight="1"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" />
    <TextView
        android:text="23.10.2010 23:34:52"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="3" />
</LinearLayout>
Sameer Segal
Thats right. However, I gave none for imageview, 0.65 for textview and 0.35 to the last textview.
Prabhat