ScrollView 卡住,直到调用 onConfigurationChaged()

发布于 2025-01-01 23:36:34 字数 1613 浏览 5 评论 0原文

正如标题所示,我有一个 ScrollView,它不会滚动,直到我将设备从纵向切换到横向或横向切换到纵向以触发 Activity 的 onConfigurationChanged() 事件。

我已经在 Nexus S (2.3.3) 和模拟器 (4.0.3) 上尝试了 Activity,它显示了相同的奇怪行为。

我也尝试过将布局应用于活动,但仍然没有运气。

我的 Activity 的 XML 布局可以在 此处 找到(它有点长,我不想弄乱我的XML 问题)。

这里有一些代码可能与你们相关,可以帮助我解决这个问题:

/** {@inheritDoc} */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.terms_and_agreements);

    //fire up the AsyncTask to get data
    showLoadingProgress();
    mBookingInfoTask = new BookingInfoTask();
    mBookingInfoTask.execute();
}

/** {@inheritDoc} */
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

/** This methode is called when the BookingInfoTask has finished collecting date from the server */
public void onBookingInfoResult(String clubTerms, String portalTerms) {
    final String fClubTerms = clubTerms;
    final String fPortalTerms = portalTerms;
    runOnUiThread(new Runnable() {
        public void run() {
            TextView tvTerms = (TextView) findViewById(R.id.tvTerms);
            tvTerms.setText(fClubTerms + "\n\n" + fPortalTerms);
        }
    });

    hideProgress(); //Hides progress bar
}

最后这是我的 Activity 的清单声明:

    <activity
        android:name=".ConfirmationActivity"
        android:configChanges="keyboardHidden|orientation"
        android:theme="@android:style/Theme.NoTitleBar" />

Like the title indicates, I have a ScrollView that doesn't scroll until I switch the device from portrait to landscape or landscape to portrait in order to trigger the onConfigurationChanged() event of my Activity.

I've tried the Activity on my Nexus S (2.3.3) and the Emulator (4.0.3) and it displays the same weird behavior.

I've also tried playing around with when the layout is applied to the Activity, still no luck.

My XML Layout for the Activity can be found here (It's slightly long, and I didn't want to clutter up my question with XML) .

Here's some code that might be relevant for you guys to look at in order to help me out:

/** {@inheritDoc} */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.terms_and_agreements);

    //fire up the AsyncTask to get data
    showLoadingProgress();
    mBookingInfoTask = new BookingInfoTask();
    mBookingInfoTask.execute();
}

/** {@inheritDoc} */
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

/** This methode is called when the BookingInfoTask has finished collecting date from the server */
public void onBookingInfoResult(String clubTerms, String portalTerms) {
    final String fClubTerms = clubTerms;
    final String fPortalTerms = portalTerms;
    runOnUiThread(new Runnable() {
        public void run() {
            TextView tvTerms = (TextView) findViewById(R.id.tvTerms);
            tvTerms.setText(fClubTerms + "\n\n" + fPortalTerms);
        }
    });

    hideProgress(); //Hides progress bar
}

And finally here's my Activity's Manifest declaration :

    <activity
        android:name=".ConfirmationActivity"
        android:configChanges="keyboardHidden|orientation"
        android:theme="@android:style/Theme.NoTitleBar" />

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

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

发布评论

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

评论(1

倦话 2025-01-08 23:36:34

我通过将我的 TextView (应该填充父级)包装在线性布局中来使其工作,如下所示:

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1" >

        <TextView
            android:id="@+id/tvTerms"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1.0"
            android:paddingBottom="6dip"
            android:paddingLeft="6dip"
            android:paddingRight="6dip"
            android:textColor="#000000" />
    </LinearLayout>

这是当我无法让它滚动时的情况:

<TextView
    android:id="@+id/tvTerms"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1.0"
    android:paddingBottom="6dip"
    android:paddingLeft="6dip"
    android:paddingRight="6dip"
    android:textColor="#000000" />

现在它像应该那样滚动了!

I got it to work by wrapping my TextView (which was supposed to fill the parent) in a Linear Layout like so:

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1" >

        <TextView
            android:id="@+id/tvTerms"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1.0"
            android:paddingBottom="6dip"
            android:paddingLeft="6dip"
            android:paddingRight="6dip"
            android:textColor="#000000" />
    </LinearLayout>

Here's how it was when I couldn't get it to scroll:

<TextView
    android:id="@+id/tvTerms"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1.0"
    android:paddingBottom="6dip"
    android:paddingLeft="6dip"
    android:paddingRight="6dip"
    android:textColor="#000000" />

And now it's scrolling like it should!

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