简体   繁体   中英

Android: EditText in ScrollView doesn't work properly

I have this layout:

<ScrollView
    android:id="@+id/scroll_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="@dimen/keyline_1"
        android:layout_above="@+id/action_bar_layout"
        android:orientation="vertical">

    ....

   <EditText
            android:id="@+id/message"
            style="@style/ItemNewsFeedMessage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"             
            android:inputType="textMultiLine"/>

</ScrollView

I tried these solutions: https://gist.github.com/laaptu/4cb395fded9a0700fcdb

Unfortunately the behavior is not correct yet: when I enter news characters at the end of EditText, the main scroll doesn't move in the same time, so I can't see my last characters set.

在此处输入图片说明

Thanks for your help guys!

Your Question is not clear enough, may be this can resolve your problem

// set request Focus

    mEditText.requestFocus(View.FOCUS_RIGHT);

layout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                android:paddingBottom="@dimen/activity_vertical_margin"
                tools:context=".MainActivity">

    <ScrollView
            android:id="@+id/scroll_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/action_bar_layout"
                android:orientation="vertical">
        <EditText
                android:id="@+id/message"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/lorem_ipsum"
                android:textSize="22sp"
                android:inputType="textMultiLine"/>
        </LinearLayout>

    </ScrollView>

</RelativeLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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