Actually i have created an array of buttons,now my question is whether it will be fit in all screen resolution or not..as i have use nexus s device and the here its working fine..i mean to say that all the buttons are arranged in perfect order..more ever when i placed background image to each buttons its work fine..now i doubt whether it works for cheaper device by the same code i have written or i have to do something extra for that.thats means whether it fit for all screen resolution..or not..the code i have written is..
LinearLayout layoutVertical = (LinearLayout) findViewById(R.id.liVLayout);
LinearLayout rowLayout=null;
LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT,1);
//Create Button
for (i = 0; i<6; i++){
rowLayout = new LinearLayout(this);
rowLayout.setWeightSum(7);
layoutVertical.addView(rowLayout,param);
for(j=0;j<7;j++){
pBtnDay[i][j]=new Button(this);
rowLayout.addView(pBtnDay[i][j],param);
pBtnDay[i][j].setOnLongClickListener(this);
pBtnDay[i][j].setOnClickListener(this);
}
}
return true;
one more thing when i try to find width and height of the buttons it return 0..why?
Using weightSum is the best solution if you know exactly how many elements you want displayed on your screen, across multiple devices. So if it shows up on, say a HTC Wildfire(LDPI) then it will also show on your Nexus(HDPI).
As for your second question, I´m assuming you are using View.getHeight() and View.getWidth() to obtain these values. Since your buttons hasn´t actually been drawn yet, Android has not designated dimension values to them, that´s why they turn up 0. If you need the width and height of these buttons in onCreate, then you need to do some math of your own 🙂