Android:ScrollView中的EditText无法正常工作

时间:2016-12-30 12:58:24

标签: android android-edittext scrollview

我有这个布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/root"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/theme_primary"
        android:orientation="vertical"
        android:visibility="invisible">

        <include layout="@layout/include_toolbar_actionbar" />

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

            <RelativeLayout
                android:id="@+id/post_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@android:color/white">

                <ScrollView
                    android:id="@+id/scroll_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scrollbars="vertical"
                    android:layout_above="@+id/action_bar_layout">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:focusableInTouchMode="true"
                        android:orientation="vertical"
                        android:paddingTop="@dimen/keyline_1">

                       <EditText
                            android:id="@+id/message"
                            style="@style/ItemNewsFeedEditMessage"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:background="@android:color/transparent"
                            android:hint="@string/news_feed_post_hint"
                            android:inputType="textMultiLine|textCapSentences"
                            android:paddingBottom="@dimen/keyline_4"
                            android:paddingLeft="@dimen/keyline_4"
                            android:paddingRight="@dimen/keyline_4"
                            android:paddingTop="@dimen/keyline_1"
                            android:overScrollMode="always"
                            android:scrollbarStyle="insideInset"
                            android:scrollbars="vertical"
                            android:gravity="top|left" />

                        <RelativeLayout
                            android:id="@+id/picture_layout"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:visibility="gone">

                            <ImageView
                                android:id="@+id/picture"
                                android:layout_width="match_parent"
                                android:layout_height="1dp"
                                android:scaleType="centerCrop" />                                  

                        </RelativeLayout>

                    </LinearLayout>

                </ScrollView>

                <LinearLayout
                    android:id="@+id/action_bar_layout"
                    android:layout_width="match_parent"
                    android:layout_height="48dp"
                    android:layout_alignParentBottom="true"
                    android:background="@android:color/white"
                    android:gravity="center_vertical"
                    android:orientation="horizontal"
                    android:paddingLeft="@dimen/keyline_1"
                    android:paddingRight="@dimen/keyline_1"
                    android:visibility="invisible">

                    ...

                </LinearLayout>

            </RelativeLayout>               

        </RelativeLayout>

    </LinearLayout>

</RelativeLayout>

我尝试了这些解决方案:https://gist.github.com/laaptu/4cb395fded9a0700fcdb

不幸的是,行为还不正确:当我在@ + id / picture中添加图片并且edittext包含很多行时,滚动会有一个奇怪的行为。

如果没有图像,如果edittext包含很多行,则滚动是正确的,因为它是edittext滚动而没有全局滚动视图。

感谢您的帮助!

0 个答案:

没有答案