我想固定页脚,但是我有一个问题。
我的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>
如果我在此处添加LinearLayout,则该应用只会显示错误。如何制作固定页脚?
示例:http://blog.maxaller.name/wp-content/uploads/2010/05/listview_footer_scrolling.png->按钮“添加项目”-固定页脚。
最佳答案
终于我明白了。
<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>
在代码内部,您必须将页脚的高度设置为listview的填充。因为这是以px为单位,并且您需要dp,所以只需对其进行转换:
float scale = getResources().getDisplayMetrics().density;
int size = (int) (FOOTERHEIGHT * scale + 0.5f);
SWIPEREFRESHLAYOUT.setPadding(0, 0, 0, size);