片段中的EditText和软键盘问题 [英] Problems with EditText and soft keyboard in a fragment

查看:61
本文介绍了片段中的EditText和软键盘问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在构建一个Android应用程序,该应用程序使用户能够拍照并写出它的详细信息.该应用程序使用Sherlock库.

I'm currently building an android application that enables users to take pictures and write details of it. The application uses Sherlock libraries.

我已经实现了一个SherlockFragment来显示图像,并实现了一些EditText和TextView来使用户键入图像信息.但是,当其中一个EditText成为焦点时,所有字段都将向上推,然后弹出软键盘.

I've implemented a SherlockFragment to display the image and a few EditText and TextView to enable users to key in information of the image. However, when one of the EditText is on focus, all the fields are pushed up and the soft keyboard pops up.

这是我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linear"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="#FFFFFF">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="200dip"
        android:layout_above="@+id/textView"
        android:layout_marginTop="20dip"
        android:layout_marginBottom="20dip"
        android:contentDescription="desc" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Title:"
        android:textStyle="bold"
        android:layout_above="@+id/editTextSimple" 
        android:layout_marginBottom="2dip"
        android:textSize="15sp"/>

     <EditText
        android:id="@+id/editTextSimple"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView1"
        android:layout_marginBottom="4dip">
        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Description:"
        android:textStyle="bold"
        android:layout_above="@+id/editTextSimple1" 
        android:layout_marginBottom="2dip"
        android:textSize="15sp"/>

    <EditText
        android:id="@+id/editTextSimple1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView2"  
        android:layout_marginBottom="12dip">
    </EditText>

    <Button android:textColor="#FF000000" 
        android:id="@+id/submitButton" 
        android:text="@string/memorySubmit" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="24dip"
        android:onClick = "submit"/>
</RelativeLayout>

据我了解,在一项活动中,必须在调用软键盘时将此<activity android:windowSoftInputMode="...." >放在Android清单中以调整视图.但是,如何为片段设置此值?

From what I understand, in an activity, one have to place this <activity android:windowSoftInputMode="...." > in the Android Manifest to adjust the view when the soft keyboard is called upon. However, how do we set this for fragments?

推荐答案

这在我使用多个布局和一个Viewtub创建消息屏幕的情况下对我有用.将此放置在onCreate()上希望对您有帮助.

this worked for me in a scenario where I was using multiple layouts and a viewstub to create a messaging screen. Place this in onCreate() Hope this helps.

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

这篇关于片段中的EditText和软键盘问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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