Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to add <ScrollView> to an android app widget layout

Tags:

android

I am trying to create a widget to an application, following is the layout I'm using. I've tried to add the scroll view to the second half part of the widget. I am unable to do that, When I removed tags, widget is getting displayed, but when with tags, android is unable to load the widget. I am scratching my head with this for two days. I don't understand what am I doing wrong?

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/background_light"
    >

        <RelativeLayout 
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/background_dark"
            android:id="@+id/widgetHeader"
            >

            <Button 
              android:background="@drawable/icon_quickword"
              android:id="@+id/widgetBtn"
              android:layout_width="wrap_content" 
              android:layout_height="wrap_content" 
              android:layout_gravity="center_vertical"
              android:layout_margin="5sp" 
             />

            <TextView android:text="@string/widget_title1"
              android:id="@+id/widget_title1" 
              android:textSize="18sp"   
              android:textStyle="bold"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_gravity="center_vertical"
              android:textColor="@android:color/white"
              android:layout_toRightOf="@id/widgetBtn"
              android:layout_marginLeft="2sp"
              />

            <TextView android:text="@string/widget_title2"
              android:id="@+id/widget_title2" 
              android:textSize="15sp"   
              android:textStyle="italic"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_gravity="center_vertical"
              android:textColor="@android:color/white"
              android:layout_toRightOf="@id/widgetBtn"
              android:layout_below="@id/widget_title1"
              android:layout_marginLeft="3sp"
              />


        </RelativeLayout>   

            <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
            >

            <LinearLayout
                android:id="@+id/widgetContent"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:background="@android:color/white"
                >

                <TextView android:text="@string/widget_content_info1"
                  android:id="@+id/widget_content_info1"
                  android:textStyle="bold" 
                  android:textSize="16sp"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center_vertical"
                  android:textColor="@android:color/black" />

                <TextView android:text="@string/widget_content_info2"
                  android:id="@+id/widget_content_info2"
                  android:textSize="14sp" 
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center_vertical"
                  android:textColor="@android:color/black" />   

                <TextView android:text="@string/widget_content_info3"
                  android:id="@+id/widget_content_info3"
                  android:textSize="14sp" 
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center_vertical"
                  android:textColor="@android:color/black" />   

            </LinearLayout>
        </ScrollView>

</LinearLayout>                                                                             
like image 996
Amol Avatar asked Feb 07 '13 04:02

Amol


1 Answers

you can use ListView with only 1 list item (your layout)

get sample for list view here

and modified ListProvider.java

public int getCount() {
return 1;
}
public RemoteViews getViewAt(int position) {
    RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.your_origin_layout);
    remoteView.setTextViewText(R.id.content, "your Text");
    // add other pocess here
    return remoteView;
}
like image 108
Pipin Indrawan Avatar answered Sep 23 '22 20:09

Pipin Indrawan