1
내 앱에서 모든 위치에 대해 퍼센트를 사용하고 싶습니다. 나는 항상 같은 시스템을 사용한다. 나는 안드로이드 프로그래밍에 새로운 사람이다. 사용량퍼센트로 위치 설정 - Android DisplayMetrics
public class SCREEN {
DisplayMetrics dm = new DisplayMetrics();
Point size_ = new Point();
int width;
int height;
// DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
SCREEN (Context CONTEXT_) {
dm = CONTEXT_.getResources().getDisplayMetrics();
int densityDpi = dm.densityDpi;
height = dm.heightPixels;
width = dm.widthPixels;
}
// get full width
public int WIDTH() {
return width;
}
public int HEIGHT(){
return height;
}
public int W(int PER_){
return width/100*PER_;
}
public int H(int PER_ ){
return height/100*PER_;
}
}
예 :
EKRAN = new SCREEN();
MENU1.setX((float) EKRAN.W(50));
이 MENU1 버튼 x 위치가 화면의 중심에 있어야하지만 밤은 것을 의미
이
클래스이다. 42 % 같은 작은 값. 플로트 여기샷 (FrameLayout이)된다 -
어쩌면 내 버그 INT 관계이다 I이 버튼이 코드를 삽입 -은 X = Y 0, = 0, 화면의 폭 = 절반을 의미하지만 되지 않습니다 :final Button BTN1 = new Button(this);
BTN1.setText(String.valueOf(EKRAN.H(0)));
BTN1.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT));
VEIW_MAIN.addView(BTN1);
BTN1.setY((float) EKRAN.H(0));
BTN1.setX((float) EKRAN.W(0));
BTN1.setWidth((int) EKRAN.W(50));
Important : This work EKRAN.WIDTH()/5 = 216 , but EKRAN.W(20) = 200
My current screen i is 1080 . Only this EKRAN.WIDTH()/2 give me 540 .
Even EKRAN.WIDTH()/100*50 give me 500 ... Where is the 40pix ?!
나는 "백분율을 사용하지 마십시오."에 대해 더 자세히 알아볼 필요가 있습니다. 내 해결책이 아닙니다. –