向上移动文本视图仅在Android上的虚拟键盘打开视图、文本、键盘、Android

2023-09-12 21:39:00 作者:我的巴掌正好适合你的脸

我的XML code是这里,

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,

执行后,当我进入上编辑文本的价值,虚拟键盘打开,整个mainlayout是向上滚动,我有这样的

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. ?

推荐答案

试试这个;也许是有用的。调整清单文件

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

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

@Ganesh更改清单像上面的活动 code也正在

@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>