개발을 하다보면, 예기치 않게 배경을 두고 그 안에 무언가를(?) 올려야 할 때가 있다.
TextView 든, EditText 든...
내가 지향하는 스타일은 아니다. 난 정상적인 Layout을 XML로 짜서 하는 것을 선호한다.
그렇지만 기획이 그렇지 못할 경우도 다반사다.
그래서 준비한 코드가 바로 아래 코드이다.
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
DPUtil dputil = DPUtil.getInstance(this);
float density = dputil.getDensity();
float densityDpi = dputil.getDensityDpi();
int deviceWidth = metrics.widthPixels;
int deviceHeight = metrics.heightPixels;
//왼쪽에서 24% 이동한 위치
int w = (int)((float)deviceWidth * 0.24f);
//상단에서 30% 아래로 이동한 위치
int h = (int)((float)deviceHeight * 0.3f);
//DPi 에 따른 폰트사이즈 조정
float font_size = 20f;
if(densityDpi <= 240.0f)
{
font_size = 18f;
}
//tv 변수는 TextView의 변수. 알아서 판단해서 변경하시면 됩니다.
//TextSize
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, font_size);
//Set Margin
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
params .setMargins(w, h, 0, 0);
tv.setLayoutParams(std_no_params);
'안드로이드 > TIP' 카테고리의 다른 글
| 유용하게 개발하기 (0) | 2017.06.21 |
|---|---|
| Status bar Icon Size (0) | 2015.03.20 |
| 해상도별 아이콘 / 스플래시 이미지 사이즈 (0) | 2015.03.06 |
| Suppressed: java.lang.ClassNotFoundException: android.support.v7.appcompat.R$styleable (0) | 2014.11.28 |
| Android Support Library AppCompat7 (0) | 2014.10.01 |



