将textview和Imagebutton嵌套在嵌套在表行中的FrameLayout中

时间:2014-10-22 13:22:51

标签: java android nested tablelayout

大家希望我能更好地解释下面我需要的东西..在此先感谢您的帮助..

我想做什么:我试图动态创建一个图像按钮表。单击每个图像按钮时,会出现一个计数器徽章/气泡(就像更新图标一样,当iphone中有更新时,您会在应用上看到)。此徽章应显示图像按钮的左上角。

我的逻辑:为此,我认为我需要创建一个tablerow,然后在该tablerow中放置一个FrameLayout,并在该FrameLayout中但是在Image按钮和将显示的文本视图中徽章图片。我使用FrameLayout的原因是因为我需要将TextView与Imagebutton重叠以获得我想要的效果...

问题:我编写了下面的代码,它运行时没有错误,但没有计数器徽章!!似乎应用程序忽略了徽章,只为我创建了图像按钮....需要帮助才能使其正常工作

帮助!!!

ContentView(R.layout.activitymenu);
TableLayout table =(TableLayout) findViewById(R.id.MenuButtonTable);


for (int row=0; row<NUM_Array_Rows;row++) {
//Set new Row in Table
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT, 0.1F));
table.addView(tableRow);


for (int col = 0; col < NUM_Array_Clns; col++) {

int x, y;
final int FINAL_COL = col;
final int FINAL_ROW = row;
final int FINAL_BtnCounter = BtnCounter;
final String SW_NAME;
float w;


final ImageButton ImButton = new ImageButton(this);
final FrameLayout FrmLayout = new FrameLayout(this);
final TextView txtView = new TextView(this);


FrameLayout.LayoutParams layout1 =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams. WRAP_CONTENT,FrameLayout.LayoutParams.WRAP_CONTENT);
FrmLayout.setLayoutParams(layout1);

ViewGroup.LayoutParams layout2 =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP _CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);

txtView.setLayoutParams(layout2);
txtView.setGravity(Gravity.TOP | Gravity.RIGHT);
txtView.setBackgroundResource(R.drawable.badge);
txtView.setText("2");
FrmLayout.setBackgroundResource(R.drawable.ic_laun cher);


ImButton.setLayoutParams(new TableRow.LayoutParams(BtnWidth, BtnHight,0.1F));
Resources res = getResources();

SW_NAME = MenuArray[col][1]; //SW NAme
temp = MenuArray[col][3];
int id = res.getIdentifier(temp, "drawable", MenuActivity.this.getPackageName());
Drawable drawable = res.getDrawable(R.drawable.sw03);
ImButton.setBackground(drawable);
BtnCounter = BtnCounter + 1;
ImButtonArray[row][col] = BtnCounter; // just storing button positions in this array

ImButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int SW_ID;
SW_ID = BtnCounter;
onPrepareOptionsMenu(FINAL_ROW, FINAL_COL);
}
});

tableRow.addView(FrmLayout);

tableRow.addView(ImButton);

FrmLayout.addView(txtView);

0 个答案:

没有答案