仅当在 android 上打开虚拟键盘时才向上移动文本视图 [英] move up text view only when virtual keyboard open on android

查看:29
本文介绍了仅当在 android 上打开虚拟键盘时才向上移动文本视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的xml代码在这里,

My xml code is here,

<?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:id="@+id/mainlayout" >

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true" 
    android:id="@+id/toplayout">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:src="@drawable/bg" />
</LinearLayout>


<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" 
    android:id="@+id/bottomlayout">
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Enter value" />
</LinearLayout>

当我执行时,我是这样的,

when i execute , i got like this,

执行后,当我在编辑文本上输入值时,虚拟键盘打开并且整个主布局向上滚动,我得到这样的

after execute , when i enter the value on edit text ,the virtual keyboard is open and the entire mainlayout is scroll up, i got like this

但我除了,顶部布局不向上滚动,只有底部布局或 textview 向上滚动.我期待这样,

But i except , the top layout not to scroll up , only the bottom layout or textview scroll up. i expect like this,

如何在打开虚拟键盘时仅滚动编辑视图.?

how to scroll only the edit view when open the virtual keyboard. ?

推荐答案

试试这个;也许它很有用.调整manifest文件

Try this; maybe it is useful. Adjust the manifest file

<activity
      android:windowSoftInputMode="adjustResize"              
      android:name=".youractivity" android:label="@string/app_name" >

@Ganesh 你改变 manifest 就像上面你的 Activity 代码也工作

@Ganesh you change manifest like above your Activity code also working

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"   >

  <RelativeLayout
     android:layout_width="fill_parent"
     android:layout_height="wrap_content" 
     android:id="@+id/toplayout">
     <ImageView
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:src="@drawable/ic_launcher" />   
     <EditText
         android:layout_width="fill_parent"
         android:layout_alignParentBottom="true"   
         android:layout_height="wrap_content"
         android:hint="Enter value" />

     </RelativeLayout>
</LinearLayout>

这篇关于仅当在 android 上打开虚拟键盘时才向上移动文本视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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