我正在開發的UI(主屏幕),就像在這個環節
http://www.flickr.com/photos/[email protected]/7023063473/Button是不是取其屬性?
- 所有的信息都從正在添加XML是可用的服務器上給出該屏幕 意味着 1在屏幕上 2號按鈕 - 大小,屏幕和按鈕的背景圖像,按鈕上的文字來自 服務器 因此我們不能使用xml來創建佈局。我已經使用了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);
創建按鈕我使用這個代碼 - 在主屏幕活動(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);
給我你的寶貴幫助....
哪些屬性無法獲取,可以提供更多詳細信息? – RobinHood 2012-03-28 05:43:46
不是拿setHeght()和setWidth()也不帶填充.. – user1282588 2012-03-28 05:45:41