私はアンドロイドを新しくしています。私はメソッドライブラリを構築しようとしています。私ははるかにJavaで快適で、実行時のすべてがJavaで発生するようだから、私はJavaでGUIを扱うメソッドを構築しようとしています。私はそれほど遠くないし、オブジェクトを描画するためにxとyの位置を定義するために離れて探している。これは私がこれまで持っているものです。Android:設定xとy pos
//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
}
だから私はボタンという名前のボタンを持っている、と私は setSizeByRatio(ボタン、25、50)を言う場合。ボタンの高さを画面の25%に設定し、高さを画面の50%に設定します。
私の主な質問は、あなたがreg javaのように描画を開始したいxとyの位置をどのように設定するのですか? 私はレイアウト(l、t、r、b)を横断しました。親に対して相対的にxとyだけを設定します。
次の質問は、GUIメソッドを学ばなければならない点ですか?これが多くの人を殺すだろうが、XMLでコメントするにはどうすればいいのだろうか?私はXMLに慣れていて、私はアンドロイドです。
チェック答えは:http://stackoverflow.com/questions/3441475/android-change-absolute-position-of-a-view-programmatically これは役立つかもしれません。 – Reena
よく考えてみましょう。私はすべてが親になければならないと思う。たとえその親がメインレイアウトであっても。私はまだ高さと幅を行うことなく、xとyの位置を設定する方法を知りたいです。 – JBreezy901
@Reenaありがとうございました。私は見た目が良くなる必要があると思う。私は良いことを探して、それを見ませんでした。 – JBreezy901