How to add multiple buttons using layout.addview() in the android platform? -


First of all, please forgive my poor English.

In one of my apps, I add several buttons, when the button number is less than 60, it is doing great work, but when there are more than 60 buttons, nothing is shown. Thread was trying to use, but with no luck

some code:

activity_main.xml

  & lt; Relative layout xmlns: android = "http://schemas.android.com/apk/ Race / Android" xmlns: device = "http://schemas.android.com/tools" Android: layout_width = "match_parent" Android: layout_height Android: paddingBottom = "@dimen / activity_vertical_margin" Android: paddingLeft = "@ Dimen / activity_horizontal_margin" Android: paddingRight = "@ Dimen / activity_horizontal_margin" Android: paddingTop = "@ Dimen / activity_vertical_margin." Tools: Reference = " MainActivity "& gt; & Lt; TextView android: id = "@ + id / tv" android: layout_width = "wrap_content" Android: layout_height = "wrap_content" android: text = "@ string / hello_world" / & gt; & Lt; scrollview Android: layout_below = "@ id / TV" Android: Layout_width = "Fill_parent" Android: Layout_height = "Wrap_content" android: orientation = "vertical" android: scrollbars = "none" & gt; & Lt; LinearLayout android: id = "@ + id / message" Android: Layout_width = "Fill_parent" Android: Layout_height = "Wrap_content" Android: Layout_gravity = "top" android: alpha = "0.7" android: gravity = "center" android: orientation = "Vertical" & gt; & Lt; Button android: id = "@ + id / newnote" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" android: onClick = "YC" Android: textSize = "18sp" / & gt; & Lt; / LinearLayout & gt; & Lt; / Scrollview & gt;  

MainActivity.java

  protected void OnCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); SetContentView (R.layout.activity_main); {DisplayMetrics dm = New Performance Metrics () for (Int i = 0; I & lt; 60; i ++); . GetWindowManager () getDefaultDisplay () getMetrics (DM) Int screenwidth = DM.width pixel; Button tv = new button (this); Tv.setLayoutParams (New LinearLayout.LayoutParams (7 * Screenwidth / 8, LinearLayout.LayoutParams.WRAP_CONTENT)); Tv.setId (i); Tv.setTextSize (18); Tv.setText ("" + i); Tv.setOnLongClickListener (New OnlineClicklist) {Public Boolean On Longclick (see V) {return false;}}); Textview textview = new textview (this); Textview.setHeight (8); Find the last linear linear lineout = (linear timepiece) VVBIID (RID.); LinearLayout.addView (TV); LinearLayout.addView (TextView); }}  

Anyway, thanks to help me.


Comments