动态生成Layout的问题 主Activity中,把GameLayout 加入到主布局中,ViewGroup parent = xxxparent.addView(GameLayout,LayoutParams()); //这个是fill_parent,如果要加点空闲就用marging 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼主的addView()使用带LayoutParams的参数试试,我这里大概帮你写了下,可能楼主还需要调试一下。public class GameLayout extends LinearLayout{ public GameLayout(Context context,ImageView[][] images) { super(context); setLayout(context,images); setBackgroundColor(Color.parseColor("#4682B4")); } private void setLayout(Context context, ImageView[][] images) { // TODO Auto-generated method stub LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); LinearLayout linearLayout=new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setLayoutParams(lp); linearLayout.setGravity(LinearLayout.TEXT_ALIGNMENT_CENTER); linearLayout.setPadding(0, 0, 0, 0); for (int i = 0; i < images.length; i++) { LinearLayout liner = new LinearLayout(context); liner.setOrientation(LinearLayout.HORIZONTAL); int leng=images[i].length; for (int j = 0; j < leng; j++) { ImageView img=(ImageView)images[i][j]; liner.addView(img); } linearLayout.addView(liner); liner.addView(img, lp); liner=null; } this.addView(linearLayout, lp); }}第二个也是如此,带LayoutParams,可能需要LinearLayout的也可能需要ViewGroup,看会不会报错。 Button的selector问题 熟悉android按键读取,分发的进!!! 短信收件人框只能搜索到导入的联系人不能搜索到新增的联系人 jdk7 keystore无法获取md5 TCL智能电视平台应用开发大赛问题专贴 请教android中有类似hook功能的函数吗? android遍历界面上的所有控件后,如何判断控件是什么类型? 为什么在Eclipse配置完Android后没有Android Project? 安卓 老是碰到程序意外停止的错误 安卓微信怎样才能实现扫码登录腾讯游戏 仿微信 android https 证书校验问题
super(context);
setLayout(context,images);
setBackgroundColor(Color.parseColor("#4682B4"));
} private void setLayout(Context context, ImageView[][] images) {
// TODO Auto-generated method stub
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
LinearLayout linearLayout=new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setLayoutParams(lp);
linearLayout.setGravity(LinearLayout.TEXT_ALIGNMENT_CENTER);
linearLayout.setPadding(0, 0, 0, 0);
for (int i = 0; i < images.length; i++) {
LinearLayout liner = new LinearLayout(context);
liner.setOrientation(LinearLayout.HORIZONTAL);
int leng=images[i].length;
for (int j = 0; j < leng; j++) {
ImageView img=(ImageView)images[i][j];
liner.addView(img);
}
linearLayout.addView(liner);
liner.addView(img, lp);
liner=null;
}
this.addView(linearLayout, lp);
}}第二个也是如此,带LayoutParams,可能需要LinearLayout的也可能需要ViewGroup,看会不会报错。