开发者

Android layout help

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 cen开发者_JS百科ter). This is row layout, so I dont want it to be very heavy. And I dont want to hard code the width in dp.


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>


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>


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜