[英]Align buttons in ScrollView to bottom of the screen and just below the above View when Softkeyboard is opened
In one Android-Activity, I have some Input-fields with some Buttons below that. 在一个Android活动中,我有一些输入字段,下面有一些按钮。 Because I don't the Softkeyboard to push everything up and want to give the user the ability to navigate to a different Input-field quite easy, i put the Input-fields and the buttons into a ScrollView.
因为我没有使用软键盘来推动所有操作,并且希望使用户能够轻松导航到其他输入字段,所以将输入字段和按钮放入ScrollView中。
Now I want the Buttons to be at the bottom of the screen, when the softkeyboard is closed 现在,当软键盘关闭时,我希望按钮位于屏幕底部
and just below the Input-fields in the ScrollView, when keyboard is opened. 打开键盘时,在ScrollView中输入字段的正下方。
If I add 如果我加
android:layout_below="@id/input_fields"
the buttons are always below the input-fields, but not at the bottom of the screen. 这些按钮始终位于输入字段下方,但不在屏幕底部。
android:layout_alignParentBottom="true"
aligns them to bottom, but when keyboard is open, they are in front of the last input-fields. 将它们对齐到底部,但是当键盘打开时,它们位于最后一个输入字段的前面。
Does anybody know what to do? 有人知道该怎么办吗?
A example of my layout-file: 我的布局文件的一个示例:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="@+id/input_fields"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<!-- some input-fields -->
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_below="@id/input_fields"
android:padding="5dp">
<!-- 2 buttons -->
</LinearLayout>
</RelativeLayout>
If you need more information: just ask! 如果您需要更多信息:请问!
Thanks for any help in advance! 感谢您的任何帮助!
EDIT: some further information: 编辑:一些进一步的信息:
With "in front of" I mean, that the Buttons were "hiding" the input-fields, because they weren't aligned to the input-fields-layout, but to the end of the parent layout (which was a RelativeLayout inside a ScrollView). “在...前面”的意思是,这些按钮“隐藏”了输入字段,因为它们未与输入字段布局对齐,而是与父级布局的末尾对齐(这是一个内部的RelativeLayout, ScrollView)。 This is gone, when I use your suggestion, but then the buttons are always visible right above the keyboard (I did it that way before, but I would like to do it a little bit different, to save some space).
当我使用您的建议时,此操作已消失,但是按钮始终在键盘上方始终可见(我以前是这样做的,但是我想做一点不同,以节省一些空间)。 I would like to have the buttons in that ScrollView right after the input-fields when the Keyboard is opened.
我希望在打开键盘时在输入字段后的那个ScrollView中具有按钮。 So that you can just see the ScrollView and if you scroll to the end of it, at the bottom (after the input-fields) you should see the buttons.
这样您就可以看到ScrollView,如果滚动到它的末尾,则在底部(在输入字段之后)您应该看到按钮。 That wont be a problem, but I want the buttons to stay at the bottom of the screen when keyboard is closed regardless of whether the ScrollView fills all the space.
不会有问题,但是无论ScrollView是否填满所有空间,我都希望按钮在关闭键盘时能保持在屏幕底部。 Would be nice if you have some ideas!
如果您有一些想法,那就太好了!
Add your fields in ScrollView
and place your buttons outside ScrollView
like this: 添加您的字段
ScrollView
,把你的按钮外ScrollView
是这样的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:id="@+id/input_fields"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- some input-fields -->
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp" >
<!-- 2 buttons -->
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
</LinearLayout>
Also use 也使用
<activity android:windowSoftInputMode="adjustResize" . . . >
in your activity tag. 在您的活动代码中。 Please check this http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
请检查此http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.