【问题标题】:move up text view only when virtual keyboard open on android仅当在 android 上打开虚拟键盘时才上移文本视图
【发布时间】:2012-06-20 12:50:03
【问题描述】:

我的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>

当我执行时,我得到了这样的结果,

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

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

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

【问题讨论】:

  • 尝试为清单文件中的活动添加 android:windowSoftInputMode="adjustPan|adjustResize"。

标签: android android-layout


【解决方案1】:

试试这个;也许它很有用。调整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>

【讨论】:

  • 为什么我们要在软键盘启动时调整视图大小?
猜你喜欢
  • 2015-05-03
  • 1970-01-01
  • 2014-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多