2

I'm able to successfully use a ScrollView inside the layout xml file for an application. However, when I tried using a ScrollView inside the layout xml file for a widget, I get a "Problem Loading Widget" error as soon as I drop the widget in the emulator. If I comment out the ScrollView, then the widget shows up in the emulator. I've pasted my layout xml file below. Any thoughts on how to get past this error would be much appreciated.

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:paddingBottom="3dip">

    <LinearLayout
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingLeft="6dip"
        android:paddingRight="6dip"
        android:paddingBottom="3dip">

        <Button 
            android:id="@+id/ok_widget"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:layout_gravity="right"
            android:text="@string/button_ok" />
    </LinearLayout>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        android:layout_marginBottom="50dip">

        <LinearLayout 
            android:id="@+id/linear_layout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingBottom="3dip">      

        </LinearLayout>

    </ScrollView>

    <RelativeLayout 
        android:layout_marginTop="-50dip" 
        android:gravity="bottom" 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent">
        <LinearLayout
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingLeft="6dip"
            android:paddingRight="6dip"
            android:paddingBottom="3dip">
            <Button 
                android:id="@+id/ok_widget"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:layout_gravity="right"
                android:text="@string/button_ok" />
        </LinearLayout>
    </RelativeLayout>
</LinearLayout>

OkieDoke
  • 21
  • 1
  • 2

2 Answers2

7

It says right on the android developer website:

A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:

* FrameLayout
* LinearLayout
* RelativeLayout

And the following widget classes:

* AnalogClock
* Button
* Chronometer
* ImageButton
* ImageView
* ProgressBar
* TextView

Descendants of these classes are not supported.

0

First, add android:scrollbarAlwaysDrawVerticalTrack="true" android:scrollbars="vertical" to your scrollview. What is the output of adb logcat when the app crash ?

Khetzal
  • 286
  • 1
  • 5
  • Do you know if it's possible to view the adb logcat from the eclipse adt plugin? If I select Windows->Show View->Error Log, the most relevant message is: AndroidManifest: Ignoring unknown 'ScrollView' XML element – OkieDoke Nov 22 '10 at 17:16
  • Yes is it possible, you need to go in the ddms view and if you have the default configuration, you can see a logcat view (I don't use so much eclipse, i don't know how to see this view more directly). – Khetzal Nov 22 '10 at 17:19
  • Here is one stack from the logcat output: 11-22 09:21:47.997: WARN/AppWidgetHostView(106): updateAppWidget couldn't find any view, using error view 11-22 09:21:47.997: WARN/AppWidgetHostView(106): android.view.InflateException: Binary XML file line #30: Error inflating class android.widget.ScrollView 11-22 09:21:47.997: WARN/AppWidgetHostView(106): at android.view.LayoutInflater.createView(LayoutInflater.java:513) – OkieDoke Nov 22 '10 at 17:25
  • Here is the other stack: 11-22 09:21:47.997: WARN/AppWidgetHostView(106): Caused by: android.view.InflateException: Binary XML file line #30: Class not allowed to be inflated android.widget.ScrollView 11-22 09:21:47.997: WARN/AppWidgetHostView(106): at android.view.LayoutInflater.failNotAllowed(LayoutInflater.java:525) 11-22 09:21:47.997: WARN/AppWidgetHostView(106): at android.view.LayoutInflater.createView(LayoutInflater.java:490) – OkieDoke Nov 22 '10 at 17:29
  • What is in your xml line 30 ? – Khetzal Nov 22 '10 at 17:31
  • Here's is xml line 30, from the full xml in the original post: – OkieDoke Nov 22 '10 at 17:36
  • After digging around a bit, it looks like scrolling is not supported in app widgets... =( http://stackoverflow.com/questions/3879748/scrollable-textview-in-android-widget http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout Guess that explains why every cell phone manufacturer (HTC, Moto, Samsung,etc.) has their own launcher and why widgets for different launchers are incompatible. – OkieDoke Nov 22 '10 at 21:01
  • 1
    Actually, this does provide an answer. The problem is a viewer needs to dig through the comments to find it. The answer should be updated to include the information @OkieDoke found. Either that or the OP should answer their own question. – Charles Caldwell May 28 '14 at 12:25