【问题标题】:Make android bottom button bar appear only when I scroll to the bottom of the page仅当我滚动到页面底部时才显示 android 底部按钮栏
【发布时间】:2012-07-20 12:53:30
【问题描述】:

在我正在设计的一个 android 4.1 应用程序中,我试图让我的底部栏具有两个动态按钮,即即使我在页面顶部也不会停留在屏幕底部.我希望它仅在用户向下滚动到页面的最后时出现。现在,无论我怎么尝试,它仍然固定在屏幕底部。我真的很感激一些帮助。 谢谢。

project_search_list.xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ListView android:id="@android:id/list"
    android:layout_width="fill_parent" android:layout_height="0dip"
    android:layout_weight="1" android:drawSelectorOnTop="false"
    />

<ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:contentDescription="@string/description"
    android:gravity="left"
    android:scaleType="fitXY" />

<TextView
    android:id="@+id/empty"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="left"
    android:text="" />

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">

<LinearLayout android:id="@+id/footer" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_alignParentBottom="true" style="@android:style/ButtonBar">

<Button android:id="@+id/prev_10_results" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:layout_weight="1"
    android:text="@string/prev_10_results" />

<Button android:id="@+id/next_10_results" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:layout_weight="1"
    android:text="@string/next_10_results" />

</LinearLayout>
</ScrollView>
</LinearLayout>

这是一个屏幕截图。注意到底部的按钮栏了吗?我希望它仅在我向下滚动到页面末尾时出现。

【问题讨论】:

    标签: android android-layout android-ui android-view android-button


    【解决方案1】:

    这应该让您开始,检查 onscrollstatechanged 与行是否可见,然后采取正确的操作,如切换或动画按钮栏,如果您使用可见性消失,列表视图将发生在按钮栏之前的部分。这样你底部就没有空白了:

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
    
        if (scrollState == 0 && mListContent.getLastVisiblePosition() == 0
                && buttonbar.getVisibility() == View.GONE) {
            toggleButtonbar();
        } else if (mListContent.getLastVisiblePosition() != 0
                && buttonbar.getVisibility() == View.VISIBLE) {
            toggleButtonbar();
        }
    }
    

    【讨论】:

    • 谢谢...让我试试这个,我会尽快回复你
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-03
    • 2019-02-27
    • 1970-01-01
    • 2014-12-24
    • 2020-01-08
    相关资源
    最近更新 更多