Reputation: 41
i want make fixed footer, but I've got a problem.
My activity_main:
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.shppandroid1.app.MainActivity">
<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ececec"
android:divider="@null"
android:dividerHeight="0dp"/>
</android.support.v4.widget.SwipeRefreshLayout>
If I add here LinearLayout, the app just shows the error. How can I make fixed footer?
Example: http://blog.maxaller.name/wp-content/uploads/2010/05/listview_footer_scrolling.png -> Button "Add Item" - it fixed footer.
Upvotes: 1
Views: 531
Reputation: 114
Finally i got it.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#0A756E"
android:gravity="center" >
<LinearLayout
android:id="@+id/ll_archiv"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tv_archiv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="@string/archiv"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#fff" />
</LinearLayout>
</RelativeLayout>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/footer"
android:layout_alignParentTop="true" >
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
Inside of your code, u have to set the height of the footer as a padding for the listview. Because this is in px and u'll need dp, just transform it:
float scale = getResources().getDisplayMetrics().density;
int size = (int) (FOOTERHEIGHT * scale + 0.5f);
SWIPEREFRESHLAYOUT.setPadding(0, 0, 0, size);
Upvotes: 2