bucky bucky - 5 months ago 11
Android Question

How to make the listview items look organized?

The list view looks so bad. Because of the orgranization. I want to make it better. I mean the colon needs to be position at constant place without moving here and there . So here is my xml code.
and you can see the image it looks so bad
list view image

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:orientation="vertical"
>

<LinearLayout
android:id="@+id/lyt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="1px"
android:gravity="left|top"
android:padding="2dp"
android:orientation="horizontal" >

<TextView
android:id="@+id/textView1"
android:layout_width="150dp"

android:layout_weight="5"
android:layout_height="wrap_content"
android:textColor="@color/darker_grey"
android:gravity="left|top"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Name"
android:textStyle="bold"/>

<TextView
android:gravity="left|top"
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_height="wrap_content"
android:textColor="@color/darker_grey"
android:paddingLeft="5dp"
android:paddingRight="10dp"
android:text=":" />

<TextView
android:textStyle="bold"
android:gravity="left|top"
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_weight="6"
android:layout_height="wrap_content"
android:textColor="@color/darker_grey"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"/>
</LinearLayout>

</LinearLayout>

Answer

Ok, now I got what you need. Use Relative layout, so you can choose where to position the nested layouts.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/login_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="hi hi"></TextView>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:text=":"></TextView>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="hey hey"></TextView>

</RelativeLayout>