我目前正在构建一个android应用程序,使用户能够拍摄照片并编写详细信息。这个应用程序使用的是Sherlock库。
我已经实现了一个SherlockFragment来显示图像,以及一些EditText和TextView来使用户能够键入图像的信息。但是,当其中一个EditText处于焦点位置时,所有字段都会向上推送,软键盘会弹出。
这是我的布局:
<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 Manifest中以调整视图。然而,我们如何为片段设置它呢?
发布于 2013-07-11 06:16:21
在我使用多个布局和一个视图存根来创建消息传递屏幕的场景中,这对我很有效。将它放在onCreate()中希望这会有帮助。
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
发布于 2012-12-26 16:43:25
一个Activity
的所有片段都具有与其父Activity
相同的行为,但是如果您需要为不同的Fragments
使用不同的键盘行为,您可以在Fragment
代码中动态更改此属性,如下所示:
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.softInputMode.SOFT_INPUT_ADJUST_PAN);
希望这能有所帮助!
发布于 2014-04-17 18:07:07
这可以在Fragment类中用来向上移动编辑文本并滚动到结尾。
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
https://stackoverflow.com/questions/14037915
复制相似问题