Android MarginLayoutParams ClassCastException在具有SwiperFresh的ListView上

Android MarginLayoutParams ClassCastException在具有SwiperFresh的ListView上,android,android-layout,Android,Android Layout,我正在ListView上实现拉刷新手势,我有一个简单的xml布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <android.support.v4.widget.SwipeRefreshLayout

我正在ListView上实现拉刷新手势,我有一个简单的xml布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v4.widget.SwipeRefreshLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swipeContainer_lgpin"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:headerDividersEnabled="true"
            android:footerDividersEnabled="true"
            android:dividerHeight="5dp"
            android:divider="@color/grey"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:orientation="vertical"
            android:scrollbarStyle="outsideOverlay" />

    </android.support.v4.widget.SwipeRefreshLayout>

    <ProgressBar
        android:id="@+id/progressbar"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_gravity="center"
        android:visibility="gone" />

</RelativeLayout>
关于我用于其他目的的非相关代码

ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams)listview.getLayoutParams();
mlp.setMargins(0, 0, 0, 300);

如果我删除SwipeRefreshLayout,它可以正常工作。为什么会发生这种情况?

SwipeRefreshLayout
没有为其子级使用扩展
MarginLayoutParams
的自定义
LayoutParams
。它只是使用了
ViewGroup.LayoutParams
。这就是为什么在xml中为
SwipeRefreshLayout的
子级设置边距不会产生任何结果


这就是为什么不能将
getLayoutParams()
的结果强制转换为
ViewGroup.MarginLayoutParams

的原因,还有其他方法吗?(在listview子项上放置下边距)根据您的具体需要,您可以:1。在
SwipeRefreshLayout
或2上设置
bottomPadding
。将
ListView
上的
bottomPadding
cliptoppadding
设置为false我以友好的方式将页脚视图放在ListView上,因为有时必须以编程的方式将其删除。谢谢
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams)listview.getLayoutParams();
mlp.setMargins(0, 0, 0, 300);