This what i get in my Activity
:
http://img855.imageshack.us/img855/2056/androidscreenshot.jpg
The activity is filled by a TableLayout
. The TableLayout
in turn is filled by 2 TableRow
that are Two View
containing a 100x100 cyan bitmap. The yellow area is the background of the activity in position (1,1) of the TableView. The red area is the background of the activity in position (1,2).
The problem is that i cannot see the other two cyan bitmap in position (2,1) and (2,2). I think the problem is that the View in the first row are resized in the width but not in the height. So the view in the first row obscure the view in the second row.
If i add to the View
both ViewGroup.LayoutParams
or LayoutParams
with WRAP_CONTENT
i get a java.lang.ArithmeticException: divide by zero
This is my code:
public class HIDActivity extends Activity
{
boolean toggle = false;
TableLayout IFaceLayout;
TableRow TButtons1;
TableRow TButtons2;
TableRow TArea;
SimpleButton TButton1;
SimpleButton TButton2;
SimpleButton TButton3;
SimpleButton TButton4;
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
TButton1 = new SimpleButton(this);
TButton2 = new SimpleButton(this);
TButton3 = new SimpleButton(this);
TButton4 = new SimpleButton(this);
TButtons1 = new TableRow(this);
TButtons2= new TableRow(this);
TButtons1.setLayoutParams(new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT , LayoutParams.WRAP_CONTENT ) );
TButtons2.setLayoutParams(new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT , LayoutParams.WRAP_CONTENT ) );
TButtons1.addView(TButton1);
TButtons1.addView(TButton2);
TButtons2.addView(TButton3);
TButtons2.addView(TButton4);
IFaceLayout = new TableLayout(this);
IFaceLayout.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT , LayoutParams.WRAP_CONTENT ) );
IFaceLayout.setStretchAllColumns(true);
IFaceLayout.addView(TButtons1);
IFaceLayout.addView(TButtons2);
setContentView(IFaceLayout);
IFaceLayout.requestLayout();
}
class SimpleButton extends View
{
BitmapDrawable ButtonImage;
Paint Style;
int i , j ;
int width , heigth;
public SimpleButton(Context context)
{
super(context);
Style = new Paint();
if(toggle == false)
{
this.setBackgroundColor(Color.YELLOW);
toggle = true;
}
else
{
this.setBackgroundColor(Color.RED);
toggle = false;
}
}
@Override
public void onDraw(Canvas canvas)
{
ButtonImage = new BitmapDrawable(Bitmap.createBitmap(100 , 100 , Bitmap.Config.RGB_565));
this.width = ButtonImage.getBitmap().getWidth();
this.heigth = ButtonImage.getBitmap().getHeight();
for(i = 0 ; i < width ; i++)
{
for(j = 0 ; j < heigth ; j++)
{
ButtonImage.getBitmap().setPixel(i, j, Color.CYAN);
}
}
canvas.drawBitmap(ButtonImage.getBitmap() , 0 , 0 , Style);
}
}
}
Could someone please help me with this problem.