【问题标题】:Overlay update button on top of listview?列表视图顶部的覆盖更新按钮?
【发布时间】:2015-06-15 16:03:46
【问题描述】:

我正在制作一个包含每 30 秒更新一次的列表视图的 android 应用程序。如果有新数据,我希望出现一个按钮,我可以在其中更新提要,类似于 facebook 应用程序。我怎样才能做到这一点?当不在列表视图中滚动时,有没有办法在出现在屏幕顶部的列表视图顶部覆盖一个按钮?

这是我的列表视图 xml:

<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">

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

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:paddingLeft="3dp"
        android:paddingRight="3dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/header"
        android:divider="@android:color/transparent"
        android:dividerHeight="10dp"
        />

</LinearLayout>

<Button
    android:id="@+id/update_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:text="Button" />

【问题讨论】:

  • 我已经实现了,但我希望用户知道何时需要更新提要。有什么建议吗?

标签: java android listview button overlay


【解决方案1】:

尝试使用setOnScrollListener 并实现onScrollStateChanged

setOnScrollListener(new OnScrollListener() {
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        // TODO Auto-generated method stub
        //make your button invisible
        button.setVisible(false);
    }

    public void onScrollStateChanged(AbsListView view, int scrollState) {
        if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
            //make your button visible.
             button.setVisible(true);

        }
    }
});

视图的叠加可见here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多