我正在开发一个像这个屏幕一样的UI(主屏幕) 在此链接中给出了 http://www.flickr.com/photos/78431491@N07/7023063473/
- 所有信息都来自xml,这在服务器上是可用的 1-屏幕上的按钮数 2-尺寸,屏幕和按钮的背景图像,按钮上的文字以及来自的每一个 服务器 所以我们不能使用xml来创建layout.I已经被选中了tabbar,当我创建的按钮没有采用我使用的任何属性代码时是 -
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
int id = getResources().getIdentifier("com.correlation.edumationui:drawable/" + img, null, null);
intent = new Intent().setClass(this, HomeScreen.class);//HomeScreen.class);
Bundle objbundle = new Bundle();
objbundle.putSerializable("screen", mscreen);
intent.putExtras(objbundle);
spec = tabHost.newTabSpec("title").setIndicator(title,getResources().getDrawable(id))
.setContent(intent);
tabHost.addTab(spec);
用于创建按钮我正在使用此代码 - 在主屏幕Activity(HomeScreen.class)
中LinearLayout buttonsView = new LinearLayout(this);
buttonsView.setOrientation(LinearLayout.VERTICAL);
for (int r = 0; r < 6; ++r)
{
Button btn = new Button(this);
btn.setText("A");
btn.setHeight(30);
btn.setWidth(224);
btn.setPadding(10,10,10,10);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); // Verbose!
lp.weight = 1.0f; // This is critical. Doesn't work without it.
buttonsView.addView(btn, lp);
}
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
setContentView(buttonsView, lp);
给我你宝贵的帮助....
答案 0 :(得分:0)
而不是
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); // Verbose!
lp.weight = 1.0f; // This is critical. Doesn't work without it.
buttonsView.addView(btn, lp);
使用
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(30, 224); // Verbose!
lp.weight = 1.0f; // This is critical. Doesn't work without it.
buttonsView.addView(btn,lp);
反映布局参数中按钮的宽度和高度。
答案 1 :(得分:0)
使用LayoutParameters设置按钮的宽度,高度和边距。
答案 2 :(得分:0)
尝试使用setLayoutParams将高度,宽度和填充设置为:
Button btn = new Button (this);
LayoutParams params = Prams // Set Params Which you want to set for your view.
btn.setLayoutPrams(params);
希望这会对你有所帮助。
答案 3 :(得分:0)
以编程方式设置高度和宽度,您可以使用如下所示的set layoutparams。
LinearLayout ly = (LinearLayout) findViewById(R.id.verify);
Button buyButton = new Button(this);
buyButton.setText("button");
buyButton.setLayoutParams(new LayoutParams(50,
50));
buyButton.setPadding(10, 10, 10, 10);
ly.addView(buyButton);