android - 使android底部按钮栏仅在我滚动到页面底部时出现

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

在我正在设计的 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>

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

screen shot

最佳答案

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

@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();
    }
}

关于android - 使android底部按钮栏仅在我滚动到页面底部时出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11579794/

相关文章:

android - 两个按钮上的语音识别器到两个编辑文本

android - 调用 Camera.takePicture Android 后禁用相机快照

android - 如何创建我自己的 Vector Drawable? (安卓)

android - 切换按钮未显示在应用程序中

android - 是否有类似 bootstrap 的 android 框架?

java - 语音识别器 : no selected voice recognition service

c# - OnlyOnRanToCompletion 和 NotOnFaulted 之间的区别?

android - 有没有办法让 View 绘制在所有其他 View 之上?

Android Border Less 按钮按下状态背景色

android - 如何渐变填充按钮的背景?