带有SoftInputMode AdjustPan的Android EditText多行 [英] Android EditText Multiline with SoftInputMode adjustPan

查看:66
本文介绍了带有SoftInputMode AdjustPan的Android EditText多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动,可在滚动视图内的多行模式下使用顶部的EditText视图的顶部栏编辑一些文本.在底部有2个按钮的另一个视图.我想要实现的是在编辑底部栏位于软键下方的文本时.在清单文件中使用android:windowSoftInputMode ="adjustPan"很容易.问题是,如果edittext变得足够大,可以多行显示,则在编辑顶部栏时它会消失.仅在使用adjustPan模式时会发生这种情况.但是最糟糕的是,我认为这是一个错误,当光标位于edittext视图的末尾并使用D-Pad游戏杆向上滚动时,所有布局都将拉到顶部.

这是没有聚焦于EditText的屏幕: http://i.stack.imgur. com/pFadV.png

当滚动发生错误时,会发生以下情况: http://i.stack.imgur .com/eS8PP.png

我的布局如下:

   <?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"
    android:background="@color/BackgroundGray"
    android:gravity="top|center"
    android:orientation="vertical"
    android:windowSoftInputMode="adjustPan" >

    <RelativeLayout
        android:id="@+id/top_bar"
        android:layout_width="fill_parent"
        android:layout_height="45dip"
        android:layout_alignParentTop="true"
        android:background="@drawable/top_bar"
        android:focusable="true"
        android:focusableInTouchMode="true" >

        <ImageView
            android:id="@+id/bar_item_priority"
            android:layout_width="4dip"
            android:layout_height="34dip"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:contentDescription="@string/priority" />

        <EditText
            android:id="@+id/bar_title"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginLeft="6dip"
            android:background="@android:color/transparent"
            android:fadingEdge="vertical"
            android:gravity="center_vertical|left"
            android:hint="@string/default_title"
            android:inputType="text|textCapSentences"
            android:paddingLeft="10dip"
            android:textColor="#f3f3f3"
            android:textColorHint="#20ffffff"
            android:textSize="20dip"
            android:textStyle="bold" >
        </EditText>
    </RelativeLayout>

    <View
        android:id="@+id/main_top_bar_shadow"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:layout_below="@+id/top_bar"
        android:background="@color/TopBarShadow" />

    <LinearLayout
        android:id="@+id/meta_bar"
        android:layout_width="fill_parent"
        android:layout_height="25dip"
        android:layout_below="@+id/main_top_bar_shadow"
        android:background="#313435"
        android:descendantFocusability="blocksDescendants" >

        <TextView
            android:id="@+id/meta_date_modified"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center_vertical|left"
            android:paddingLeft="10dip"
            android:paddingRight="10dip"
            android:paddingTop="6dip"
            android:shadowColor="#1d1d1d"
            android:shadowDx="1"
            android:shadowDy="1"
            android:shadowRadius="2"
            android:text="@string/default_date"
            android:textColor="#9d9d9d"
            android:textSize="12dip"
            android:textStyle="bold" >
        </TextView>
    </LinearLayout>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/bottom_bar"
        android:layout_below="@+id/meta_bar"
        android:fillViewport="true"
        android:scrollbarSize="2dip"
        android:scrollbarThumbHorizontal="@drawable/scrollbar"
        android:scrollbarThumbVertical="@drawable/scrollbar"
        android:scrollbars="vertical" >

        <view
            android:id="@+id/note"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:capitalize="sentences"
            class="home.greven.notes.NoteEditor$LinedEditText"
            android:fadingEdge="vertical"
            android:gravity="top"
            android:paddingBottom="8dip"
            android:paddingLeft="11dip"
            android:paddingRight="11dip"
            android:paddingTop="8dip"
            android:textSize="16sp" >
        </view>
    </ScrollView>

    <View
        android:id="@+id/bottom_bar_shadow"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:layout_above="@+id/bottom_bar"
        android:background="@color/TopBarShadow"
        android:focusable="false"
        android:focusableInTouchMode="false" />

    <LinearLayout
        android:id="@+id/bottom_bar"
        android:layout_width="fill_parent"
        android:layout_height="40dip"
        android:layout_alignParentBottom="true"
        android:background="@drawable/bottom_buttons_bar"
        android:descendantFocusability="blocksDescendants" >

        <Button
            android:id="@+id/bottom_bar_button_plaintext"
            style="@style/NoteEditorButtonText"
            android:layout_width="0.0dip"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_margin="4dip"
            android:layout_weight="0.5"
            android:background="@drawable/small_blue_buttonstates"
            android:text="@string/plain_text" />

        <Button
            android:id="@+id/bottom_bar_button_checklist"
            style="@style/NoteEditorButtonText"
            android:layout_width="0.0dip"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_margin="4dip"
            android:layout_weight="0.5"
            android:background="@drawable/small_gray_buttonstates"
            android:onClick="toChecklist"
            android:text="@string/checklist" />
    </LinearLayout>

</RelativeLayout>

如果我在android:windowSoftInputMode中使用AdjustResize,则一切正常,但是在编辑时底部栏将可见,这是我不希望发生的事情.我认为此滚动问题是Android错误.任何帮助将不胜感激!

解决方案

底部的按钮确实有相同的问题.经过数天的谷歌搜索,我发现这是由于缺少

  android:isScrollContainer="false"

在ScrollView中.

Android文档提及此

如果视图将用作滚动容器,请设置此值 可以调整其大小以缩小其整体窗口,以便 输入法的空间.

修改: 还要检查答案

I have an activity to edit some text with a top bar a EditText view in multiline mode inside a scrollview. At the bottom another view with 2 buttons. What I wanted to achieve is when editing the text that bottom bar would be below the softkeyboard. That is easy using android:windowSoftInputMode="adjustPan" in the manifest. The problem is if the edittext becomes big enough with several lines, when editing the topbar it disappears. This only occurs when using adjustPan mode. But the worst and I think it's a bug, its when the cursor is at the end of the edittext view and scrolling up using the D-Pad joystick all the layout is pulled to the top.

This is the screen without focus on the EditText: http://i.stack.imgur.com/pFadV.png

When the bug occurs with the scrolling, this happens: http://i.stack.imgur.com/eS8PP.png

My layout is the following:

   <?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"
    android:background="@color/BackgroundGray"
    android:gravity="top|center"
    android:orientation="vertical"
    android:windowSoftInputMode="adjustPan" >

    <RelativeLayout
        android:id="@+id/top_bar"
        android:layout_width="fill_parent"
        android:layout_height="45dip"
        android:layout_alignParentTop="true"
        android:background="@drawable/top_bar"
        android:focusable="true"
        android:focusableInTouchMode="true" >

        <ImageView
            android:id="@+id/bar_item_priority"
            android:layout_width="4dip"
            android:layout_height="34dip"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:contentDescription="@string/priority" />

        <EditText
            android:id="@+id/bar_title"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginLeft="6dip"
            android:background="@android:color/transparent"
            android:fadingEdge="vertical"
            android:gravity="center_vertical|left"
            android:hint="@string/default_title"
            android:inputType="text|textCapSentences"
            android:paddingLeft="10dip"
            android:textColor="#f3f3f3"
            android:textColorHint="#20ffffff"
            android:textSize="20dip"
            android:textStyle="bold" >
        </EditText>
    </RelativeLayout>

    <View
        android:id="@+id/main_top_bar_shadow"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:layout_below="@+id/top_bar"
        android:background="@color/TopBarShadow" />

    <LinearLayout
        android:id="@+id/meta_bar"
        android:layout_width="fill_parent"
        android:layout_height="25dip"
        android:layout_below="@+id/main_top_bar_shadow"
        android:background="#313435"
        android:descendantFocusability="blocksDescendants" >

        <TextView
            android:id="@+id/meta_date_modified"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center_vertical|left"
            android:paddingLeft="10dip"
            android:paddingRight="10dip"
            android:paddingTop="6dip"
            android:shadowColor="#1d1d1d"
            android:shadowDx="1"
            android:shadowDy="1"
            android:shadowRadius="2"
            android:text="@string/default_date"
            android:textColor="#9d9d9d"
            android:textSize="12dip"
            android:textStyle="bold" >
        </TextView>
    </LinearLayout>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/bottom_bar"
        android:layout_below="@+id/meta_bar"
        android:fillViewport="true"
        android:scrollbarSize="2dip"
        android:scrollbarThumbHorizontal="@drawable/scrollbar"
        android:scrollbarThumbVertical="@drawable/scrollbar"
        android:scrollbars="vertical" >

        <view
            android:id="@+id/note"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:capitalize="sentences"
            class="home.greven.notes.NoteEditor$LinedEditText"
            android:fadingEdge="vertical"
            android:gravity="top"
            android:paddingBottom="8dip"
            android:paddingLeft="11dip"
            android:paddingRight="11dip"
            android:paddingTop="8dip"
            android:textSize="16sp" >
        </view>
    </ScrollView>

    <View
        android:id="@+id/bottom_bar_shadow"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:layout_above="@+id/bottom_bar"
        android:background="@color/TopBarShadow"
        android:focusable="false"
        android:focusableInTouchMode="false" />

    <LinearLayout
        android:id="@+id/bottom_bar"
        android:layout_width="fill_parent"
        android:layout_height="40dip"
        android:layout_alignParentBottom="true"
        android:background="@drawable/bottom_buttons_bar"
        android:descendantFocusability="blocksDescendants" >

        <Button
            android:id="@+id/bottom_bar_button_plaintext"
            style="@style/NoteEditorButtonText"
            android:layout_width="0.0dip"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_margin="4dip"
            android:layout_weight="0.5"
            android:background="@drawable/small_blue_buttonstates"
            android:text="@string/plain_text" />

        <Button
            android:id="@+id/bottom_bar_button_checklist"
            style="@style/NoteEditorButtonText"
            android:layout_width="0.0dip"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_margin="4dip"
            android:layout_weight="0.5"
            android:background="@drawable/small_gray_buttonstates"
            android:onClick="toChecklist"
            android:text="@string/checklist" />
    </LinearLayout>

</RelativeLayout>

If I use adjustResize in android:windowSoftInputMode everything works well but then the bottom bar will be visible when editing, something I didn't want to happen. I think this scrolling issue is an Android bug. Any help would be very appreciated!

解决方案

I do have the same problem with the button at the bottom. After days of googling i found this is due to the missing

  android:isScrollContainer="false"

in the ScrollView.

Android document mention this

Set this if the view will serve as a scrolling container, meaing that it can be resized to shrink its overall window so that there will be space for an input method.

Edit: Also check this Answer

这篇关于带有SoftInputMode AdjustPan的Android EditText多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆