Advertisement
Guest User

Untitled

a guest
Apr 25th, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. <Button
  2. android:id="@+id/BtnRating1"
  3. android:layout_weight="1"
  4. android:layout_height="wrap_content"
  5. android:text="@string/Rating_1"
  6. android:drawableTop="@drawable/face_1"
  7. style="?android:attr/borderlessButtonStyle"
  8. android:background="?android:selectableItemBackground"
  9. android:gravity="center"
  10. android:onClick="OnRating_1" />
  11.  
  12. View view = LayoutInflater.from(context).inflate(R.layout.button_view);
  13. Button button = (Button) view.findViewById(R.id.BtnRating1);
  14.  
  15. Button myButton = new Button(this);
  16. myButton.setText("Push Me");
  17.  
  18. LinearLayout ll = (LinearLayout)findViewById(R.id.BtnRating1);
  19. LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
  20. ll.addView(myButton, lp);
  21.  
  22. Button btn = new Button(ActivityContext);
  23.  
  24. RelativeLayout.LayoutParams btnparamLayoutParams = new RelativeLayout.LayoutParams(
  25. RelativeLayout.LayoutParams.MATCH_PARENT, 90);
  26. btn.setGravity(Gravity.CENTER_VERTICAL);
  27. btnparamLayoutParams.height = adjustedDp;
  28. btn1paramLayoutParams.setMargins(0, 0, 0, 100);
  29. btn.setLayoutParams(btnparamLayoutParams);
  30. btn.setBackgroundColor(Color.WHITE);
  31.  
  32. LinearLayout ll = (LinearLayout)findViewById(R.id.linID);
  33. ll.addView(btn)
  34.  
  35. 1. create a table row layout with button and inflate it.
  36. 2. you can create button dynamically and add it in your table row see below code for creating buttons dynamically .
  37.  
  38. TableRow.LayoutParams params = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,TableRow.LayoutParams.WRAP_CONTENT);
  39. Button button = new Button(this);
  40. params.weight = 1;
  41. params.gravity = Gravity.CENTER;
  42. tablerow.addView(button,params);
  43. here this is context of activity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement