1

I have a custom ListView.
I want to add a fixed button on the bottom of the screen.

How should I change my layout?

My screen XML code:

 <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=".ListAdapter" >

    <ImageView
        ... />

    <TextView
        ... />

</RelativeLayout>

My custom arrayAdapter source code:

 @Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.msg_detail_layout, parent, false);
    msgBodyCustomer = (TextView) rowView.findViewById(R.id.MsgBodyCustomer);
    contactImageCustomer = (ImageView) rowView.findViewById(R.id.PhotoImageCustomer);
    if(!smslist.get(position).getType().equals(INBOX)){
        msgBodyOwner.setText(smslist.get(position).getBody()); 
       contactImageCustomer .setImageURI((smslist.get(position).getPicture()));
    return rowView;
}
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
LMT
  • 11
  • 4

2 Answers2

0

Edited:try this

 <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=".ListAdapter" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button5"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <ListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/listView7"
        android:layout_alignRight="@+id/PhotoImageOwner"
        android:layout_above="@+id/button5" />

</RelativeLayout>
Charaf Eddine Mechalikh
  • 1,248
  • 2
  • 10
  • 20
0

Alternatively, you can add footer for your custom listview

The footer will always be at bottom

Code :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="7dip"
    android:paddingBottom="7dip"
    android:orientation="horizontal"
    android:gravity="center">

    <ImageView 
        android:id="@+id/footer_image" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center"
     />

    <TextView 
        android:text="@string/footer_text_1" 
        android:id="@+id/footer_text" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
     />
    </LinearLayout>
</LinearLayout> 

Refer above in your java file onCreate() where you are initialising your listview:

View footerView = ((LayoutInflater) ActivityContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
<your_list_view>.addFooterView(footerView);

Reference credit to : this answer

Community
  • 1
  • 1
Kushal
  • 8,100
  • 9
  • 63
  • 82