1

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_lyout. 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);
Phantômaxx
  • 37,352
  • 21
  • 80
  • 110
Ginso
  • 757
  • 13
  • 31

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,646
  • 2
  • 13
  • 28