将SwipeRefreshLayout与叠加模式ActionBar结合使用时,加载动画将显示在操作栏后面,使其几乎不可见.
我可以做些什么来在动作栏上显示它吗?
我想用listView实现滚动刷新功能.此外,如果列表为空,则在同一布局文件中还有其他视图元素.这是我的布局文件.问题是,当我向下滚动然后尝试向上滚动时,而不是一直滚动到顶部然后刷新它只是在那里刷新并向上滚动不起作用.
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="64dp"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/inbox_empty" />
<TextView
android:id="@+id/noEventsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="16dp"
android:layout_toRightOf="@+id/noEventsIcon" />
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_alignParentBottom="true"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:background="@color/dividerOnBlack" />
</RelativeLayout>
<ListView
android:id="@+id/list_items"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:cacheColorHint="@android:color/transparent"
android:choiceMode="multipleChoice"
android:descendantFocusability="afterDescendants"
android:divider="@android:color/transparent"
android:dividerHeight="0px"
android:scrollbars="none" />
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的onScroll方法.
@Override
public void onScroll(AbsListView view,int firstVisibleItem,int visibleItemCount,int totalItemCount) {
// If the total item count is zero and the previous isn't, assume the …Run Code Online (Sandbox Code Playgroud) 从底部拉出时有没有办法SwipeRefreshLayout刷新ListView?
我从顶部创建拉,但我也需要从底部拉.有很多关于如何从顶部创建pull的教程,但我找不到任何从底部拉的教程?
我正在尝试将SwipeRefreshLayout与WebView一起使用.
我正面临着问题,在页面中间,当用户向下滚动时,不必要的刷新开始.
如何在webview的滚动位置位于顶部时才进行刷新事件.(即,他正在查看页面的顶部)?
我一直在IllegalArgumentException: pointerIndex out of range崩溃中得到一些崩溃,我不明白发生了什么.它不仅限于一个Android构建或设备,它发生在各种设备上的5.0.1,4.4.4,4.4.2,4.0.4,2.3.6.以下是更多上下文的完整日志输出.
java.lang.RuntimeException: Unable to destroy activity {com.mypackage.myapp/com.mypackage.myapp.MyListActivity}: java.lang.IllegalArgumentException: pointerIndex out of range
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3671)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3689)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3889)
at android.app.ActivityThread.access$900(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
Caused by: java.lang.IllegalArgumentException: pointerIndex out of range
at android.view.MotionEvent.nativeGetAxisValue(MotionEvent.java)
at android.view.MotionEvent.getY(MotionEvent.java:1998)
at android.support.v4.view.MotionEventCompatEclair.getY(MotionEventCompatEclair.java:35)
at android.support.v4.view.MotionEventCompat$EclairMotionEventVersionImpl.getY(MotionEventCompat.java:95)
at android.support.v4.view.MotionEventCompat.getY(MotionEventCompat.java:228)
at android.support.v4.widget.SwipeRefreshLayout.onTouchEvent(SwipeRefreshLayout.java:772)
at android.view.View.dispatchTouchEvent(View.java:8388)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2398)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2158)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2400)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
at android.view.ViewGroup.cancelTouchTarget(ViewGroup.java:2340)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4156)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4136)
at android.view.ViewGroup.removeView(ViewGroup.java:4068)
at …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中实现了SwipeRefreshLayout.我需要更改必须向下滚动的高度来调用onRefresh()方法.我应该使用哪种方法来添加自定义高度?
SwipeRefreshLayout的实现
private SwipeRefreshLayout swipeLayout;
Run Code Online (Sandbox Code Playgroud)
在oncreate
swipeLayout = (SwipeRefreshLayout)view.findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorScheme(android.R.color.holo_blue_dark,
android.R.color.holo_green_dark,
android.R.color.holo_purple,
android.R.color.holo_orange_dark);
swipeLayout.setSoundEffectsEnabled(true);
Run Code Online (Sandbox Code Playgroud)
在onrefresh方法中实现AsyncTask
@Override
public void onRefresh()
{
// Asynctask to perform some task
}
Run Code Online (Sandbox Code Playgroud) 我现在正在使用一个应用程序,它使用3个选项卡,每个选项卡都包含一个片段,我试图在每个片段中实现SwipeRefreshLayout.我相信我已经正确地创建了这个,但我继续得到错误:
android.view.InflateException: Binary XML file line #1: Error inflating class SwipeRefreshLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.SwipeRefreshLayout" on path: DexPathList[[zip file "/data/app/com.ryan.brooks.fropllc.frop.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.ryan.brooks.fropllc.frop.app-1, /vendor/lib, /system/lib]]
at com.ryan.brooks.fropllc.frop.app.whatsGoingOnFragment.onCreateView(whatsGoingOnFragment.java:23)
Run Code Online (Sandbox Code Playgroud)
现在我完全不知道造成这种情况的原因.如果有人能帮助我,那将非常感激.
这是我实现SwipeRefreshLayout的片段布局:
<SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipe_refresh_whats_going_on">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#343434"></ScrollView>
</SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的片段类,我在调用SwipeRefreshLayout.
public class WhatsGoingOnFragment extends Fragment {
private SwipeRefreshLayout swipeLayout;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.whats_going_on_fragment, container, false);
// Retrieve the SwipeRefreshLayout and ListView instances
swipeLayout = …Run Code Online (Sandbox Code Playgroud) 我有以下布局
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
//some views here
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="*" >
</TableLayout>
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
问题是当我向下滚动表格时,我无法再次滚动,因为正在触发swipelayout.仅当表的第一个视图可见时,如何触发swiperefresh?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--<include-->
<!--android:id="@+id/app_bar"-->
<!--layout="@layout/app_bar" />-->
<android.support.design.widget.CoordinatorLayout
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/app_bar">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="256dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="64dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/header"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbarTutorial"
android:layout_width="match_parent"
android:layout_height="50dp"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<TextView
android:id="@+id/textViewAppBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:gravity="center"
android:scrollbarDefaultDelayBeforeFade="@id/toolbarTutorial"
android:text="test"
android:textColor="@color/white"
android:textSize="30sp" />
</android.support.design.widget.CollapsingToolbarLayout>
<!--<android.support.design.widget.TabLayout-->
<!--android:id="@+id/tabLayout"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--app:layout_scrollFlags="scroll|enterAlways"/>-->
</android.support.design.widget.AppBarLayout>
<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">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<!--<android.support.v4.widget.SwipeRefreshLayout-->
<!--android:id="@+id/activity_main_swipe_refresh_layout"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content">-->
<LinearLayout
android:id="@+id/linearLayoutWithData"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"> …Run Code Online (Sandbox Code Playgroud) 我正在使用android数据绑定库.如果我想让视图可见,我可以写这样的东西:
<TextView
android:id="@+id/label_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@{habitListViewModel.message}"
app:visibility="@{habitListViewModel.hasError ? View.VISIBLE : View.GONE}" />
Run Code Online (Sandbox Code Playgroud)
是否有以类似(xml)方式绑定到swipeRefreshLayout的刷新属性的选项?
目前我通过调用setRefreshing(true/false)在代码中设置它,但是希望在xml中使它保持一致.