我想在调用SwipeRefreshLayout Listener时调整整个布局?这个东西在android中是否可能。
这是我的整个xml layout.SwipeRefreshLayout包含一个进度条和FrameLayout,它包含在RelativeLayout中。所以我希望FrameLyout在我调用刷新时应该拉下来。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_navigation_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_layout" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:id="@+id/horizontal_sync_progress"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/gradient_bg_end"
android:indeterminateDrawable="@drawable/progress_drawable"
android:progressDrawable="@drawable/progress_drawable"
android:visibility="gone"/>
<FrameLayout
android:id="@+id/container_frag"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
答案 0 :(得分:1)
<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">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swp1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<-----Your design here------>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
试试这个。你必须在上面设置你的SwipeRefreshLayout。希望它能帮到你。如果这没有帮助你问我有什么问题我会帮助你
我的班级代码在
之下 mSwipeRefreshLayout1 = (SwipeRefreshLayout) findViewById(R.id.swp1);
//set colors if you need
mSwipeRefreshLayout1.setColorSchemeResources(R.color.colorPrimary, R.color.colorPrimaryDark, R.color.colorPrimaryLight);
mSwipeRefreshLayout1.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
mSwipeRefreshLayout1.setRefreshing(true);
try {
//Refresh data
} catch (Exception e) {
//Toast.makeText(getActivity(), String.valueOf(e.getMessage()), Toast.LENGTH_SHORT).show();
//customtoast.ShowToast(getActivity(), String.valueOf(e.getMessage()), R.layout.red_toast);
}
}
});
答案 1 :(得分:0)
你可以像这样编码
swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
new class(getActivity(), listView, progressBar, mApp.getPreference().getString(Common.u_id, ""), "all", swipe).execute();
}
});
return view;
}
在xml文件中包含以下代码
<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">
//your xml codes
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>