【问题标题】:android layout with header, scrollview and footer, footer comes up with keyboard带有页眉、滚动视图和页脚的 android 布局,页脚带有键盘
【发布时间】:2012-03-20 08:39:04
【问题描述】:

我需要一个带有页眉和页脚的片段。介于两者之间的内容(当然)需要是可滚动的。到那里一切都很好。 但是滚动视图内部需要是一个edittext,所以在某个时刻键盘会出现。不幸的是,键盘也会显示页脚,或者当我将 windowSoftInputMode 更改为 adjustPan 时,它会隐藏页眉。

简而言之,我想要实现的是页脚保持在底部,但滚动视图的内容向上滚动(当键盘获得编辑文本的焦点时)。标题也需要一直可见。

关于如何完成此行为的任何建议?

【问题讨论】:

  • 我有同样的问题...adjustPan 并没有真正做到,因为滚动不起作用(我的内容在 ScrollView 内)
  • 我在以下链接中遇到了类似的问题。我的活动有顶部工具栏作为标题和包含页脚按钮的视图层次结构。 stackoverflow.com/questions/10599451/…

标签: android android-scrollview android-keypad


【解决方案1】:

你试过 android:isScrollContainer="false" 吗?

【讨论】:

  • 在滚动视图上?还是页脚?还是...?
  • 在滚动视图上?还是页脚?要么...?编辑:当我将 isScrollContainer 放在滚动视图上时,它的行为与我使用 AdjustPan 时的行为相同,所以不是我真正想要的
  • 不...设法解决了一点...我认为如果您尝试在 TOP 容器中绘制(包含操作栏)...但还没有尝试过
【解决方案2】:

Android 页眉页脚和可滚动内容(正文)

您可以尝试以下方法:

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

    <LinearLayout
        android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:padding="10dp" >

        <TextView
            android:id="@+id/TextView01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="header"
            android:textSize="40sp" >
        </TextView>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:padding="10dp" >

        <TextView
            android:id="@+id/TextView02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="footer"
            android:textSize="40sp" >
        </TextView>
    </LinearLayout>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/footer"
        android:layout_below="@id/header" >

        <LinearLayout
            android:id="@+id/body"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <EditText
                android:id="@+id/edit1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp" />

            <EditText
                android:id="@+id/edit2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp" />

            <EditText
                android:id="@+id/edit3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp" />

            <EditText
                android:id="@+id/edit4"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp" />

            <EditText
                android:id="@+id/edit5"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp" />

            <EditText
                android:id="@+id/edit6"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp" />

            <EditText
                android:id="@+id/edit7"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp" />

            <EditText
                android:id="@+id/edit8"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp" />

            <Button
                android:id="@+id/btn"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Submit" />
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

android:windowSoftInputMode="adjustPan" 添加到您在 Android 清单中的活动中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-11
    • 2013-02-04
    • 1970-01-01
    • 2011-09-01
    相关资源
    最近更新 更多