android - 仅当在 Android 上打开虚拟键盘时才向上移动 TextView

标签 android android-layout

我的xml代码在这里,

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

当我执行时,我得到了这个,

enter image description here

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

enter image description here

但我除外,顶部布局不向上滚动,只有底部布局或 TextView 向上滚动。我希望这样, enter image description here

如何在打开虚拟键盘时只滚动编辑 View 。 ?

最佳答案

试试这个;也许它是有用的。调整manifest文件

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

@Ganesh 你改变 manifest 就像上面你的 Activity 代码一样有效

 <?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 - 仅当在 Android 上打开虚拟键盘时才向上移动 TextView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11119967/

相关文章:

android - 我可以在 genymotion 中添加任何 mi 设备虚拟设备吗

android - 未找到 EOCD 签名

android - WorkManager 应用程序崩溃

android - OkHttp 忽略日志记录拦截器

android - StaggeredGridLayoutManager 重新排序项目

java - 获取 Android 中复选框指向的表行?

android - Activity 开始时的动画会跳帧

android - 底部导航 View 显示不正确

android - 一项 Activity 和所有其他 fragment

android - 自定义 android 微调器