Android 在包含片段的主活动中拉入刷新
我在谷歌上搜索了很多,但没有找到适合我的答案 我想实现拉入刷新。我已经浏览了下面的所有链接,但每个链接都给出了活动中简单ListView或ScrollView的示例 这里我有一个包含4个片段的活动,我想实现pull-to-refresh。我该怎么做呢 任何形式的帮助都将不胜感激。 下面是我的活动XML代码:Android 在包含片段的主活动中拉入刷新,android,android-fragments,pull-to-refresh,Android,Android Fragments,Pull To Refresh,我在谷歌上搜索了很多,但没有找到适合我的答案 我想实现拉入刷新。我已经浏览了下面的所有链接,但每个链接都给出了活动中简单ListView或ScrollView的示例 这里我有一个包含4个片段的活动,我想实现pull-to-refresh。我该怎么做呢 任何形式的帮助都将不胜感激。 下面是我的活动XML代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andr
<?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:background="@color/homePageBackground"
android:orientation="vertical" >
<fragment
android:id="@+id/announcementHomefragment"
android:name="in.test.app.AnnouncementFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/homePageBackground" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:background="@color/homePageBackground" >
<TextView
android:id="@+id/newsTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="@string/new_list"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white"
android:textStyle="bold" />
<fragment
android:id="@+id/newshomefragment"
android:name="in.test.app.NewsFragment"
android:layout_width="wrap_content"
android:layout_height="265dp"
android:layout_below="@id/newsTitle"
android:layout_marginTop="-15dp" />
<TextView
android:id="@+id/productTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/newshomefragment"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="@string/product_in_home"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white"
android:textStyle="bold" />
<fragment
android:id="@+id/proCategoryhomefragment"
android:name="in.test.app.CategoryFragment"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:layout_below="@id/productTitle"
android:layout_marginTop="-15dp" />
<TextView
android:id="@+id/trainingTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/proCategoryhomefragment"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginTop="2dp"
android:gravity="center"
android:text="@string/trainings_in_home"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white"
android:textStyle="bold" />
<fragment
android:id="@+id/trainingfragment"
android:name="in.test.app.TrainingFragment"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:layout_below="@id/trainingTitle"
android:layout_marginBottom="10dp"
android:layout_marginTop="-15dp" />
</RelativeLayout>
</ScrollView>
编辑:
现在我使用的是SwipeRefreshLayout。它工作得很好。但是当我向下滚动滚动我的滚动视图并试图向上滚动时,它不会向上滚动,它不再工作,而是刷新。请建议我如何完成这件事。只需创建一个类扩展
SwipeRefreshLayout
并覆盖方法canChildScrollUp()
。如果要向下滚动查看列表视图
,则返回true
比如说,
@override.
boolean canChildScrollUp()
{
return Listview.getFirstVisibleItemPostion()!=0;
}
正如您在上面看到的,我没有xml中的列表视图。那我该怎么办?