点击EditText布局整体上移

iphilo 2017-02-22 11:06:08
在AndroidManifest中添加属性 android:windowSoftInputMode="stateHidden|adjustPan",可以在点击EditText后让其置于键盘之上,但是整个布局都会被顶上去,包括ActionBar,怎么做才能保证ActionBar不上移,只让中间的内容被顶上去呢
...全文
755 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_27388009 2017-07-13
  • 打赏
  • 举报
回复
楼主,最后这个问题怎么解决的,小弟也遇到了
ganshenml 2017-02-23
  • 打赏
  • 举报
回复
引用 7 楼 iphilo 的回复:
[quote=引用 6 楼 ganshenml 的回复:] [quote=引用 5 楼 iphilo 的回复:] [quote=引用 3 楼 ganshenml 的回复:] 将EditText放在ScrollView中
我试了把EditText嵌套在ScrollView里、把整个布局嵌套在ScrollView里、把除了自己的ActionBar的其它部分嵌套在ScrollView里,但是还是没效果啊,是ScrollView需要添加什么属性吗,还是需要在JAVA代码中对ScrollView进行什么处理?[/quote] 然后在ScrollView中加一个属性:android:fillViewport="true"[/quote] 您能帮我看看我的布局吗,我加了这个属性还是不行
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBack"
    tools:context="com.example.administrator.ChatActivity">

    <!--这是自定义的AtionBar,这部分也会被顶出布局-->
    <include layout="@layout/namebar"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">
        <!--这里是要显示的内容,我希望的效果是点击EditText后只有这部分上移-->
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycleview_message"
            android:layout_height="match_parent"
            android:layout_width="match_parent" />

    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true">
        <!--这个布局里包括EditText-->
        <include layout="@layout/sendbar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/include_send"/>

    </ScrollView>

</LinearLayout>
[/quote] 你的代码不全,给你写了个案例,你运行下就知道效果了:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_scroll_view_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.administrator.apptest.activity.other.ScrollViewLayoutAct">

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

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="100dp"
            android:hint="第一栏" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:hint="第二栏" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:hint="第三栏" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:hint="第四栏" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:hint="第五栏" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:hint="第六栏" />
    </LinearLayout>

</ScrollView>
iphilo 2017-02-23
  • 打赏
  • 举报
回复
引用 8 楼 ganshenml 的回复:
[quote=引用 7 楼 iphilo 的回复:] [quote=引用 6 楼 ganshenml 的回复:] [quote=引用 5 楼 iphilo 的回复:] [quote=引用 3 楼 ganshenml 的回复:] 将EditText放在ScrollView中
我试了把EditText嵌套在ScrollView里、把整个布局嵌套在ScrollView里、把除了自己的ActionBar的其它部分嵌套在ScrollView里,但是还是没效果啊,是ScrollView需要添加什么属性吗,还是需要在JAVA代码中对ScrollView进行什么处理?[/quote] 然后在ScrollView中加一个属性:android:fillViewport="true"[/quote] 您能帮我看看我的布局吗,我加了这个属性还是不行
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBack"
    tools:context="com.example.administrator.ChatActivity">

    <!--这是自定义的AtionBar,这部分也会被顶出布局-->
    <include layout="@layout/namebar"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">
        <!--这里是要显示的内容,我希望的效果是点击EditText后只有这部分上移-->
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycleview_message"
            android:layout_height="match_parent"
            android:layout_width="match_parent" />

    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true">
        <!--这个布局里包括EditText-->
        <include layout="@layout/sendbar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/include_send"/>

    </ScrollView>

</LinearLayout>
[/quote] 你的代码不全,给你写了个案例,你运行下就知道效果了:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_scroll_view_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.administrator.apptest.activity.other.ScrollViewLayoutAct">

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

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="100dp"
            android:hint="第一栏" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:hint="第二栏" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:hint="第三栏" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:hint="第四栏" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:hint="第五栏" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:hint="第六栏" />
    </LinearLayout>

</ScrollView>
[/quote] 终于找到问题所在了,太感谢了
iphilo 2017-02-22
  • 打赏
  • 举报
回复
要是用adjustResize的话,ActionBar倒是不会上移了,但是EditText就不能置于键盘之上了,会被键盘覆盖,而且中间的内容也不会上移
寒冰大神 2017-02-22
  • 打赏
  • 举报
回复
试试 android:windowSoftInputMode="stateHidden|adjustResize"
iphilo 2017-02-22
  • 打赏
  • 举报
回复
引用 6 楼 ganshenml 的回复:
[quote=引用 5 楼 iphilo 的回复:] [quote=引用 3 楼 ganshenml 的回复:] 将EditText放在ScrollView中
我试了把EditText嵌套在ScrollView里、把整个布局嵌套在ScrollView里、把除了自己的ActionBar的其它部分嵌套在ScrollView里,但是还是没效果啊,是ScrollView需要添加什么属性吗,还是需要在JAVA代码中对ScrollView进行什么处理?[/quote] 然后在ScrollView中加一个属性:android:fillViewport="true"[/quote] 您能帮我看看我的布局吗,我加了这个属性还是不行
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBack"
    tools:context="com.example.administrator.ChatActivity">

    <!--这是自定义的AtionBar,这部分也会被顶出布局-->
    <include layout="@layout/namebar"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">
        <!--这里是要显示的内容,我希望的效果是点击EditText后只有这部分上移-->
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycleview_message"
            android:layout_height="match_parent"
            android:layout_width="match_parent" />

    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true">
        <!--这个布局里包括EditText-->
        <include layout="@layout/sendbar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/include_send"/>

    </ScrollView>

</LinearLayout>
ganshenml 2017-02-22
  • 打赏
  • 举报
回复
引用 5 楼 iphilo 的回复:
[quote=引用 3 楼 ganshenml 的回复:] 将EditText放在ScrollView中
我试了把EditText嵌套在ScrollView里、把整个布局嵌套在ScrollView里、把除了自己的ActionBar的其它部分嵌套在ScrollView里,但是还是没效果啊,是ScrollView需要添加什么属性吗,还是需要在JAVA代码中对ScrollView进行什么处理?[/quote] 然后在ScrollView中加一个属性:android:fillViewport="true"
iphilo 2017-02-22
  • 打赏
  • 举报
回复
引用 3 楼 ganshenml 的回复:
将EditText放在ScrollView中
我试了把EditText嵌套在ScrollView里、把整个布局嵌套在ScrollView里、把除了自己的ActionBar的其它部分嵌套在ScrollView里,但是还是没效果啊,是ScrollView需要添加什么属性吗,还是需要在JAVA代码中对ScrollView进行什么处理?
qq_34772386 2017-02-22
  • 打赏
  • 举报
回复
试试 android:windowSoftInputMode="stateHidden|adjustResize"
ganshenml 2017-02-22
  • 打赏
  • 举报
回复
将EditText放在ScrollView中

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧