下面带有按钮的 ScrollView 在 TabHost 内滚动不同

发布于 2024-11-03 22:03:15 字数 4189 浏览 1 评论 0原文

我有一个 Activity,它由一个大滚动视图(包含 EditText 字段)和一个锚定到屏幕底部的按钮(不是滚动视图的一部分)组成。这是一个显示我所看到的问题的简单示例。我的应用程序的清单为所有活动指定 android:windowSoftInputMode = adjustmentPan。

如果我直接运行此活动,所有内容都会正确显示,并且滚动视图会按预期在编辑字段之间滚动。

我没有足够的积分来发布图像或 >2 个超链接.....

无 TabHost - 编辑第一个字段

如果我将此 Activity 作为 TabHost 的内容运行,则滚动似乎会停止。每当 EditText 获得焦点时,活动就会正确地平移到“编辑”字段。但是,它也会将按钮强制显示在屏幕上。

TabHost 内部 - 编辑第一个字段 - 该按钮来自哪里

我尝试过使用 LinearLayout(按钮的边距为负)和relativelayout为此 Activity 创建布局,两者都表现出相同的问题,即在滚动 3 个 EditText 字段时按钮始终可见。

有没有人以前见过类似的东西或者知道如何让滚动在 TabHost 内正常工作??????

LinearLayout 版本

<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="fill_parent"
    android:layout_marginBottom="60dip"
    >
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        >       
        <EditText android:id="@+id/e1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dip"
            android:layout_marginBottom="30dip"
            android:hint="edit text 1"
            />
        <EditText android:id="@+id/e2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dip"
            android:layout_marginBottom="30dip"
            android:hint="edit text 2"
            />
        <EditText android:id="@+id/e3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dip"
            android:layout_marginBottom="30dip"
            android:hint="edit text 3"
            />
    </LinearLayout>
</ScrollView>
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button"
    android:layout_marginTop="-60dip"
    android:layout_gravity="center"
    />

relativelayout 版本

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    />
<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_above="@+id/button1"
    >
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        >       
        <EditText android:id="@+id/e1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dip"
            android:layout_marginBottom="30dip"
            android:hint="edit text 1"
            />
        <EditText android:id="@+id/e2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dip"
            android:layout_marginBottom="30dip"
            android:hint="edit text 2"
            />
        <EditText android:id="@+id/e3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dip"
            android:layout_marginBottom="30dip"
            android:hint="edit text 3"
            />
    </LinearLayout>
</ScrollView>

提前致谢。

I have an Activity that consists of a large scrollview (that contains EditText fields) along with a button that is anchored to the bottom of the screen (not part of the scrollView). This is a simple example to display the issue I am seeing. The manifest for my app specifies android:windowSoftInputMode = adjustPan for all Activities.

If I run this Activity directly, everything is displayed correctly and the scrollview scrolls between the edit fields as it should.

I don't have enough points to post images or >2 hyperlinks.....

No TabHost - edit first field

If I run this Activity as the content of a TabHost, the scrolling seems to be borked. Whenever an EditText gains focus, the activity properly pans to the Edit field. However, it also forces the button onto the screen.

Inside TabHost - edit first field - Where did that button come from

I have tried creating the layout for this Activity using a LinearLayout (with negative margin for the button) as well as a RelativeLayout, and both exhibit the same issue with the button always being visible when scrolling through the 3 EditText fields.

Has anyone seen anything like this before or have any idea how to get the scrolling to work properly inside the TabHost ?????

LinearLayout version

<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="fill_parent"
    android:layout_marginBottom="60dip"
    >
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        >       
        <EditText android:id="@+id/e1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dip"
            android:layout_marginBottom="30dip"
            android:hint="edit text 1"
            />
        <EditText android:id="@+id/e2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dip"
            android:layout_marginBottom="30dip"
            android:hint="edit text 2"
            />
        <EditText android:id="@+id/e3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dip"
            android:layout_marginBottom="30dip"
            android:hint="edit text 3"
            />
    </LinearLayout>
</ScrollView>
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button"
    android:layout_marginTop="-60dip"
    android:layout_gravity="center"
    />

RelativeLayout Version

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    />
<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_above="@+id/button1"
    >
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        >       
        <EditText android:id="@+id/e1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dip"
            android:layout_marginBottom="30dip"
            android:hint="edit text 1"
            />
        <EditText android:id="@+id/e2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dip"
            android:layout_marginBottom="30dip"
            android:hint="edit text 2"
            />
        <EditText android:id="@+id/e3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dip"
            android:layout_marginBottom="30dip"
            android:hint="edit text 3"
            />
    </LinearLayout>
</ScrollView>

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄居人 2024-11-10 22:03:15

如果这对其他人有帮助......

TabHost 内托管的所有活动都有 android:windowSoftInputMode = adjustmentPan。

但是,托管 TabHost 的 Activity 缺少 android:windowSoftInputMode = adjustmentPan。
添加后,平移就可以在 TabHost 内部或 TabHost 外部进行平移。

In case this helps someone else.....

All the Activities that were hosted inside the TabHost had android:windowSoftInputMode = adjustPan.

However, the Activity that hosted the TabHost was missing android:windowSoftInputMode = adjustPan.
Once I added that, the panning worked the smae inside a TabHost or outside the TabHost.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文