2

I'm coding a widget for the first time and I have an instance of RemoteViews that contains a LinearLayout with the id R.id.linear_layout. At some point I need to change the orientation of that LinearLayout (inside the onUpdate method of my AppWidgetProvider). How can I do that?

RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
                    R.layout.widget_layout);
// change the orientaion of the linearLayout
appWidgetManager.updateAppWidget(widgetId, remoteViews);
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Ginso
  • 459
  • 17
  • 33

1 Answers1

0

RemoteViews won't let you modify the actual orientation property. Two potential work-arounds:

Approach #1

Use the constructor for that purpose: RemoteViews(RemoteViews landscape, RemoteViews portrait)

Approach #2

In your main layout file, include both a horizontal and a vertical LinearLayout, both of which carry the same information (they have identical children). Then, selectively display one or the other:

if( useVertical )
{
    remoteViews.setViewVisibility( R.id.linear_lyout_horizontal, View.GONE );
    remoteViews.setViewVisibility( R.id.linear_lyout_vertical, View.VISIBLE );
}
greeble31
  • 4,894
  • 2
  • 16
  • 30