Search code examples
androidandroid-widgetandroid-scrollview

ScrollView stuck until onConfigurationChaged() is called


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" />

Solution

  • 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!