我正在制作一项功能,允许用户在应用程序中的任何位置下拉页面,以检查他们是否与数据库服务器有连接。我已经关注了这个网站,但它需要Scrollview或ListView才能运行。我的所有布局都只在RelativeLayout中。有没有办法在不将整个布局转换为ScrollView的情况下执行此操作?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.infomaninc.appinlisv2.NewClaim">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="@+id/rlHeader" >
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#1BB52D"
android:gravity="center"
android:padding="3dp"
android:id="@+id/rlFooter" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/footer_value"
android:id="@+id/tvFooter"
android:textColor="#fff"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/app_name"
android:id="@+id/tvLoggedOn"
android:textColor="#fff"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</RelativeLayout>
不要介意代码的内容。它只是一个页面的片段。 如果我的页面看起来像这样,我将如何实现下拉刷新?
到目前为止,我已遵循本教程:https://guides.codepath.com/android/Implementing-Pull-to-Refresh-Guide#step-2-setup-swiperefreshlayout
答案 0 :(得分:6)
您还可以查找 $(".Create").on("click", function (e) {
var Id=$(this).atrr('id');
$('#Load').empty();
//overflow: visible !important;
e.preventDefault();
$('#Load').dialog({
autoOpen: true,
modal: true,
draggable: true,
resizable: false,
height: 500,
width: 600,
position: { my: "center", at: "center", of: window },
dialogClass: 'fixed-dialog',
title: 'Create New Word',
open: function (event, ui) {
$(this).load("/Dictionary/_Create");
},
//close: function (event, ui) {
// window.location.href = window.location.href;
//}
});
return false;
});
。虽然它需要SwipeRefreshLayout
作为孩子,但由于所有数据都显示在一个页面中,因此无关紧要。只需记住在ScrollView/ListView
中设置android:fillViewport="true"
,您就可以了。您可以按如下方式继续:
ScrollView
答案 1 :(得分:3)
我不确定使用RelativeLayout
是否是您的强制性要求,但您可以将所有RelativeLayout
放入ScrollView
。然后添加OnScrollListener
进行刷新。
<ScrollView>
<RelativeLayout>
// all your relativelayout
</RelativeLayout>
</ScrollView>
中的Java代码
scrollView.getViewTreeObserver().addOnScrollChangedListener(new OnScrollChangedListener() {
@Override
public void onScrollChanged() {
//example
View view = (View) scrollView.getChildAt(0);
int diff = (view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY()));
if(diff == 0 || scrollView.getScrollY() == 0 ){
Toast.makeText(getApplicationContext(),"Refresh",Toast.LENGTH_SHORT).show();
}
}
});
更新
给定的示例检测ScrollView
在向下滚动时到达底部,向上滚动时到达顶部。可以使用scrollview和子属性来创建刷新逻辑。