布局没有移动,当其内部到Android中的SwipeRefreshLayout?

时间:2016-06-22 10:17:53

标签: android swiperefreshlayout

我使用SwipeRefreshLayout。这就是我的需要...... 我在SwipeRefreshLayout中使用了一个Linearlayout,它位于" RED COLOR "中。 当我试图拉下那个布局时,那个布局没有移动。只有它显示刷新圆形箭头,但我想拉下整个" 红色"布局。怎么做到这一点?

请查阅我的资料来源。

建议请....

mylayout.xml

<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">


<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipeRefreshLayout_emptyView"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:background="#ff0000"
    >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            android:gravity="center"
            >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Sample SwipeRefreshLayout"
                android:layout_marginTop="50dp"
                android:textColor="#ffffff" />

        </LinearLayout>
    </ScrollView>

</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>

MyClass.java

public class MyClass extends Fragment implements SwipeRefreshLayout.OnRefreshListener {

private SwipeRefreshLayout swipeLayout;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.mylayout,null);


    swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeRefreshLayout_emptyView);
    onCreateSwipeToRefresh(swipeLayout);


    return  view;
}

private void onCreateSwipeToRefresh(SwipeRefreshLayout swipeLayout) {

    swipeLayout.setOnRefreshListener(this);
    swipeLayout.setColorSchemeColors(android.R.color.holo_green_dark,  android.R.color.holo_red_dark,
            android.R.color.holo_blue_dark,   android.R.color.holo_orange_dark);

}


@Override
public void onRefresh() {

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
}

3 个答案:

答案 0 :(得分:0)

而不是使用ScrollView作为SwipeRefreshLayout的孩子,请尝试使用Relativelayout / LinearLayout并使ScrollView成为其中的子项。

类似的东西:

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipeRefreshLayout_emptyView"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    >
   <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ff0000">
       <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            //Leave the interior the same

       </ScrollView>
   </LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>

同时将红色应用于LinearLayout。您目前在SwipeRefreshLayout

中拥有它

答案 1 :(得分:0)

你的ScrollView的高度不应该是wrap_content,而是match_parent

答案 2 :(得分:0)

使用PullRefreshLayout代替SwipeRefreshLayout。 Visit this sample

我有点高兴,我找到了自己的问题的解决方案。 LOL

相关问题