1. 根据不同的形式修改button需要重写
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int w = <calculation>
int h = <calculation>
setMeasuredDimension(w, h);
}
2.
这里的随机数不仅仅是数字还可能是别的
final String alphabet = "0123456789ABCDE";
final int N = alphabet.length();
Random r = new Random();
for (int i = 0; i < 50; i++) {
System.out.print(alphabet.charAt(r.nextInt(N)));
}