I am new to android. I am starting to try and build a methods library. I am much more comfortable in java, and since everything in run time seems to happen in java, I am trying to build methods dealing with the GUI in java. I do not have much so far and I am looking for away to define at what x and y pos to draw objects. This is what I have so far:
//method to get width or Xpos that is a one size fits all
public int widthRatio(double ratioIn){
DisplayMetrics dm = new DisplayMetrics(); //gets screen properties
getWindowManager().getDefaultDisplay().getMetrics(dm);
double screenWidth = dm.widthPixels; //gets screen height
double ratio = screenWidth/100; //gets the ratio in terms of %
int displayWidth = (int)(ratio*ratioIn); //multiplies ratio desired % of screen
return displayWidth;
}
//method to get height or Ypos that is a one size fits all
public int heightByRatio(double ratioIn){
DisplayMetrics dm = new DisplayMetrics(); //gets screen properties
getWindowManager().getDefaultDisplay().getMetrics(dm);
double screenHeight = dm.heightPixels; //gets screen height
double ratio = screenHeight/100; //gets the ratio in terms of %
int newHeight = (int)(ratio*ratioIn); //multiplies ratio by desired % of screen
return newHeight;
}
//sets size of any view (button, text, ...) to a one size fits all screens
public void setSizeByRatio(View object, int width, int height){
ViewGroup.LayoutParams params = object.getLayoutParams(); // gets params of view
params.width = widthRatio(width); // sets width by portion of screen
params.height = heightByRatio(height); // sets height by portion of screen
}
So if I have a Button named button, and I say setSizeByRatio(button, 25, 50); its sets the button height to 25% percent of the screen and its height to 50% of any screen.
My main question is how do you set the x and y position that you want it to start drawing like you would in reg java? I ran across layout(l, t, r, b); but it only sets the x and y relative to the parent.
Next questions are what else as far as GUI methods should I learn? and I know this is going to kill alot of people but how do I comment in XML? I am as new to XML as I am to android.