我有后续的布局:
<com.example.CustomSwipeRefreshLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/include" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/header_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</com.example.CustomSwipeRefreshLayout>
带有固定标题和可滚动列表。 CustmoSwipeRefreshLayout是一个扩展SwipeRefreshLayout的类:
public class CustomSwipeRefreshLayout extends SwipeRefreshLayout {
private ListView childListView;
public CustomSwipeRefreshLayout(Context context) {
super(context);
}
public CustomSwipeRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setChildListView(ListView childListView) {
this.childListView = childListView;
}
@Override
public boolean canChildScrollUp() {
return childListView.getFirstVisiblePosition() != 0;
}
(其中childListView是id为lv的小部件)。此代码无法正常工作。实际上,进度循环出现在两种情况中: - 我将listview刷到顶部 - 我在标题上进行滑动手势,listview的第一个元素可见。
如果我将listview刷到顶部(现在可以正常工作),并且如果我在标题和列表视图上进行滑动手势不是顶部元素,那么我会想要进展圆圈两者
答案 0 :(得分:0)
我遇到了同样的问题,我的解决方案在我的父布局中设置了android:clickable="true"
。试试这样:
<com.example.CustomSwipeRefreshLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/include" >
<LinearLayout
android:clickable="true" <!-- this line -->
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/header_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</com.example.CustomSwipeRefreshLayout>