【问题标题】:Pull the whole layout down on swipeRefreshLayoutListener android在 swipeRefreshLayoutListener android 上拉下整个布局
【发布时间】:2017-02-17 06:32:50
【问题描述】:

我想在调用 SwipeRefreshLayout Listener 时将整个布局下移?这件事在android中可能吗? 这是我的整个 xml 布局。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>

【问题讨论】:

  • 你现在尝试了什么?请发布一些代码
  • 你必须在 xml 文件的顶部设置 SwipeRefreshLayout。
  • ya..我会分享我的 xml
  • set SwipeRefreshLayout android:layout_height="wrap_content" 它解决了我的问题
  • 请贴出完整的xml代码

标签: android android-scrollview pull-to-refresh swiperefreshlayout


【解决方案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);
                    }
                }
            });

【讨论】:

  • @Divya 这对你有帮助吗?如果这可以帮助您将此作为正确答案,以便其他人从中获得帮助
  • 慢点...你刚刚发布了这个答案。
  • @Zaki 它不会在调用 swipeRefreshLayoutListener 时拉下布局。我想拉下框架布局。该怎么做?
  • 我将添加一张图片,以帮助您理解我的查询。
  • @Divya 请提供完整的 xml 代码。我认为您发布了一半代码
【解决方案2】:

你可以这样编码

   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>

【讨论】:

    猜你喜欢
    • 2014-03-01
    • 1970-01-01
    • 2016-12-28
    • 1970-01-01
    • 1970-01-01
    • 2016-06-02
    • 2021-09-23
    • 2012-02-17
    • 1970-01-01
    相关资源
    最近更新 更多