sadegh sadegh - 2 months ago 13
Android Question

(Eclipse) move item to top of listveiw

i create custom listveiw but item of list go bottom of list

my activity xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="ir.sheikhoo.sis.ListuniActivity"
android:background="@drawable/bg2" >

<LinearLayout
android:id="@+id/linearLayoutBottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="14dp" >

<Button
android:id="@+id/btnCancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:text="@string/list_activity_btn_cancel" />

<Button
android:id="@+id/btnReload"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:text="@string/list_activity_btn_ok" />
</LinearLayout>

<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/linearLayoutBottom"
android:dividerHeight="0dp" />

</RelativeLayout>


and this is list_row.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp">

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_university_white" />

<TextView
android:id="@+id/uniName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/imageView1"
android:textColor="@color/white_color"
android:text="@string/list_title" />

<ImageView
android:id="@+id/next_ic"
android:layout_width="15dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:src="@drawable/next_ic"
android:layout_centerVertical="true" />

</RelativeLayout>

Answer

The issue is that you have android:layout_above="@+id/linearLayoutBottom" on your ListView. Since it is wrapping content, it only wraps the vertical content that is inside of it, and since you have it constrained above the button linear layout, it's staying there. You probably want to remove the above constraint and try adding android:alignParentTop="true" on your ListView

Comments