gpt4 book ai didi

android - 全屏 ScrollView

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:47:45 24 4
gpt4 key购买 nike

我必须在全屏模式下开发一个应用程序,现在我有一个公式带有一些文本编辑器和一些按钮。如果键盘弹出它隐藏两个按钮,所以我将所有内容都放入 ScrollView 中:

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
tools:context="controller.RegsiterActivity" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
android:id="@+id/register_textview_firstname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:singleLine="true"
android:text="@string/text_firstname" />

<EditText
android:id="@+id/register_textedit_firstname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:inputType="text" />

<TextView
android:id="@+id/register_textview_lastname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:singleLine="true"
android:text="@string/text_lastname" />

<EditText
android:id="@+id/register_textedit_lastname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:inputType="text" />

<TextView
android:id="@+id/register_textview_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:singleLine="true"
android:text="@string/text_email" />

<EditText
android:id="@+id/register_textedit_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:inputType="textEmailAddress" />

<TextView
android:id="@+id/register_text_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:singleLine="true"
android:text="@string/text_password" />

<EditText
android:id="@+id/register_textedit_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:inputType="text" />

<Button
android:id="@+id/register_button_register"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button_register" />

<Button
android:id="@+id/register_button_cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button_cancel" />

</LinearLayout>

</ScrollView>

正如我所说,我必须全屏运行我的应用程序:

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

但是当我现在运行我的应用程序时,没有出现 scrollView,也没有滚动工作。

我怎样才能使 scrollView 工作?

最佳答案

您应该添加到 ScrollView 的第一个属性是:

android:fillViewport="true" 

当设置为 true 时,此属性会导致 ScrollView 的子项在需要时扩展到 ScrollView 的高度。当子级高于 ScrollView 时,该属性无效。

此外,将 fill_parent 布局尺寸更改为 match_parent,因为 fill_parent 已弃用,您可以摆脱任何烦人的警告。

此外,将 LinearLayoutlayout_height 属性更改为 match_parent 以便它会随 ScrollView 一起调整大小屏幕配置更改,例如拉起键盘。

此外,与@karvoynistas 的建议类似,您应该看看 windowSoftInputMode属性(property)。

您可以将此属性添加到您的 Activity 中:

<activity
android:windowSoftInputMode="stateVisible|adjustResize"
...>

<!-- ... -->

</activity>

这样做的效果是(根据 Android docs ):

To ensure that the system resizes your layout to the available space—which ensures that all of your layout content is accessible (even though it probably requires scrolling)

adjustPan 值添加到 windowSoftInputMode 属性可能有效,但并不是您想要的,因为它可能会导致一些异常影响(请阅读下文)。

Android Docs 两个值的比较:

调整调整大小

The activity's main window is always resized to make room for the soft keyboard on screen.

调整平移

The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

关于android - 全屏 ScrollView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26562402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com