Advertisement
Guest User

Untitled

a guest
Jun 6th, 2012
1,794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. How to setLayoutParams on dynamically added elements on Widget
  2. RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_design);
  3.  
  4. RemoteViews newView = new RemoteViews(context.getPackageName(), R.layout.widget_item);
  5. views.addView(R.id.view_container, newView);
  6.  
  7. LinearLayout item = (LinearLayout) ((Activity) context).findViewById(R.id.widgetItem);
  8. MarginLayoutParams marginParams = new MarginLayoutParams(item.getLayoutParams());
  9. marginParams.setMargins(10, 50, 4, 5);
  10. LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(marginParams);
  11. item.setLayoutParams(layoutParams);
  12.  
  13. LinearLayout layoutParams = item.getLayoutParams();
  14. layoutParams.setMargins(10, 50, 4, 5);
  15. item.setLayoutParams(layoutParams);
  16.  
  17. private static void adjustViewHeight(int resID, int pixels, Activity activity){
  18. ((FrameLayout.LayoutParams)activity.findViewById(resID).getLayoutParams()).bottomMargin = pixels;
  19. activity.findViewById(resID).invalidate();
  20. activity.findViewById(resID).requestLayout();
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement