简体   繁体   English

Android:滚动视图内的视图被键盘隐藏

[英]Android: Views within scroll view are hidden by keyboard

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <VideoView
                android:id="@+id/uploadedVideo"
                android:layout_width="match_parent"
                android:layout_height="224dp" />

            <TextView
                android:id="@+id/tvPath"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/uploadedVideo"
                android:padding="5dp"
                android:lines="1"
                android:hint="choose video"/>

            <EditText
                android:id="@+id/etTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/tvPath"
                android:hint="Your title here"/>

            <EditText
                android:id="@+id/etDescription"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/etTitle"
                android:hint="Your description here"/>

            <Button
                android:id="@+id/btnUpload"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:text="upload"/>

        </RelativeLayout>

    </ScrollView>

</LinearLayout>

I created a layout as above. 我如上所述创建了一个布局。 The problem here is, when I click the edit texts and the keyboard comes out, the scroll view is stretched only little so the edit texts are hidden by the keyboard. 这里的问题是,当我单击编辑文本并弹出键盘时,滚动视图仅被拉伸很小,因此键盘隐藏了编辑文本。 The button moves above the keyword, but again it's the two edit texts that are hidden by the keyboard. 该按钮移到关键字上方,但同样是键盘隐藏的两个编辑文本。

Keeping Scrollview as parent is making both editText visible when the keyboard is up. 保持Scrollview为父级,可以在键盘启动时使两个editText都可见。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

                <VideoView
                    android:id="@+id/uploadedVideo"
                    android:layout_width="match_parent"
                    android:layout_height="224dp" />

                <TextView
                    android:id="@+id/tvPath"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/uploadedVideo"
                    android:padding="5dp"
                    android:lines="1"
                    android:hint="choose video"/>

                <EditText
                    android:id="@+id/etTitle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/tvPath"
                    android:hint="Your title here"/>

                <EditText
                    android:id="@+id/etDescription"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/etTitle"
                    android:hint="Your description here"/>

                <Button
                    android:id="@+id/btnUpload"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:text="upload"/>

            </LinearLayout>

        </ScrollView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM