【问题标题】:Scrollview does not scroll when keyboard appears出现键盘时Scrollview不滚动
【发布时间】:2015-02-02 15:07:50
【问题描述】:

我的 RelativeLayout 中有一些 EditText,并在其底部对齐了一个按钮。当键盘弹出时,我希望我的布局调整大小(因此,我使用 android:windowSoftInputMode="adjustResize")并且还希望它可以滚动,因为在较小的屏幕上调整大小是不够的。

问题是我根本无法滚动!

我确实需要按钮留在屏幕底部。

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

    <!-- some hidden RelativeLayouts, filling the whole screen -->

<RelativeLayout
        android:id="@+id/form_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent" android:layout_height="match_parent"
            android:fillViewport="true" android:layout_above="@+id/ok_btn">

        <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" android:background="#99000000" android:visibility="visible">

            <View
            android:id="@+id/shade"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_alignTop="@+id/logradouro1"
            android:background="#FFF" android:layout_marginTop="-30dp"/>

            <!-- some visible EditTexts and TextViews here -->

        </RelativeLayout>

    </ScrollView>

    <Button android:id="@+id/ok_btn"
            android:layout_width="match_parent"
            android:layout_height="50dp" android:background="@color/verdeBotao" android:text="Cadastrar"
            android:textColor="#FFF" android:layout_alignParentBottom="true"/>

</RelativeLayout>


</RelativeLayout>

下面是 2 个屏幕截图来说明正在发生的事情。请注意,当键盘启动时我无法滚动。 谢谢!

【问题讨论】:

    标签: android scrollview android-softkeyboard android-input-method


    【解决方案1】:

    我正在发布与您的用户界面类似的内容。为底部的按钮设置一个 RelativeLayout。将重力设置为底部,您的按钮视图应该 android:layout_alignParentBottom="true"

    <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/m_table_menu" >
    
            <LinearLayout
                android:id="@+id/layuserdetails"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:orientation="horizontal"
                android:padding="5dp" >
    
                Yourviewss......i guess edittexts 
    
            </LinearLayout>
        </ScrollView>
    

    //可滚动按钮布局

     <RelativeLayout
            android:id="@+id/m_table_menu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="bottom"
            android:padding="0dp" >
    
            <LinearLayout
                android:id="@+id/laysharepost"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:gravity="bottom"
                android:orientation="vertical"
                android:padding="5dp" >
    
    //replace textview with buttonview.. 
                <TextView
                    android:id="@+id/share_tvcommentdone"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:background="@drawable/button_selector"
                    android:padding="10dp"
                    android:text="POST"
                    android:textColor="@android:color/white" />
            </LinearLayout>
        </RelativeLayout>
    

    【讨论】:

    • 你不使用 ScrollView 吗?我想我应该用它来处理小屏幕
    • 我想我的问题与在 ScrollView 的视图中设置 android:layout_alignParentBottom="true" 有关
    • 为什么不将线性布局作为根元素。试一试。
    猜你喜欢
    • 2018-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 2013-02-25
    相关资源
    最近更新 更多