SwipeRefreshLayout setRefreshing没有显示最初的指标最初、指标、SwipeRefreshLayout、setRefreshing

2023-09-12 10:44:48 作者:再見小時候

我有一个非常简单的布局,但是当我把我的片段setRefreshing(真)的onActivityCreate它最初不显示。这只能说明,当我做一拉刷新。任何想法,为什么它不是显示了最初?

XML片段:

 < android.support.v4.widget.SwipeRefreshLayout
机器人:ID =@ + ID / swipe_container
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:工具=htt​​p://schemas.android.com/tool​​s
机器人:layout_width =match_parent
机器人:layout_height =match_parent
>

<滚动型
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>

    < RelativeLayout的
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:方向=垂直>

    < / RelativeLayout的>


< /滚动型>
< /android.support.v4.widget.SwipeRefreshLayout>
 

片段code:

 公共静态类LinkDetailsFragment扩展BaseFragment实现SwipeRefreshLayout.OnRefreshListener {

    @InjectView(R.id.swipe_container)
    SwipeRefreshLayout mSwipeContainer;

    公共静态LinkDetailsFragment的newInstance(字符串subreddit,字符串LINKID){
        捆绑的args =新包();
        args.putString(EXTRA_SUBREDDIT,subreddit);
        args.putString(EXTRA_LINK_ID,LINKID);

        LinkDetailsFragment片段=新LinkDetailsFragment();
        fragment.setArguments(参数);

        返回片段;
    }

    公共LinkDetailsFragment(){
    }

    @覆盖
    公共无效onActivityCreated(包savedInstanceState){
        super.onActivityCreated(savedInstanceState);

        mSwipeContainer.setOnRefreshListener(本);
        mSwipeContainer.setColorScheme(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);
        mSwipeContainer.setRefreshing(真正的);
    }

    @覆盖
    公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,捆绑savedInstanceState){
        最后查看rootView = inflater.inflate(R.layout.fragment_link_details,集装箱,假);
        ButterKnife.inject(这一点,rootView);
        返回rootView;
    }

    @覆盖
    公共无效onRefresh(){
        //刷新
    }
}
 

解决方案

面对同样的问题。我的解决方案 -

  mSwipeRefreshLayout.post(新的Runnable(){
    @覆盖
    公共无效的run(){
        mSwipeRefreshLayout.setRefreshing(真正的);
    }
});
 

I have a very simple layout but when I call setRefreshing(true) in onActivityCreate of my fragment it does not show initially. It only shows when I do a pull to refresh. Any ideas why it isnt showing up initially?

Fragment xml:

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_container"
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"
>

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

    </RelativeLayout>


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

Fragment code:

public static class LinkDetailsFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener {

    @InjectView(R.id.swipe_container)
    SwipeRefreshLayout mSwipeContainer;

    public static LinkDetailsFragment newInstance(String subreddit, String linkId) {
        Bundle args = new Bundle();
        args.putString(EXTRA_SUBREDDIT, subreddit);
        args.putString(EXTRA_LINK_ID, linkId);

        LinkDetailsFragment fragment = new LinkDetailsFragment();
        fragment.setArguments(args);

        return fragment;
    }

    public LinkDetailsFragment() {
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        mSwipeContainer.setOnRefreshListener(this);
        mSwipeContainer.setColorScheme(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);
        mSwipeContainer.setRefreshing(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View rootView = inflater.inflate(R.layout.fragment_link_details, container, false);
        ButterKnife.inject(this, rootView);
        return rootView;
    }

    @Override
    public void onRefresh() {
        // refresh
    }
}

解决方案

Faced with same issue. My solution -

mSwipeRefreshLayout.post(new Runnable() {
    @Override
    public void run() {
        mSwipeRefreshLayout.setRefreshing(true);
    }
});