본문 바로가기

width

[Android] ImageView를 Width 길이에 맞춰 Height 조절 ImageView에 이미지를 그냥 넣을 경우, 화면 사이즈에 맞게 이미지가 자동으로 늘어나면 좋으려만,그렇지 않습니다. 딱! 이미지 사이즈 만큼만 뿌려주게 되지요. 그럼 어떻게 하면 될까요???아주 간단 합니다. 아래 와 같이 adjustViewBounds를 true로 해주면 됩니다. 이렇게 해주면, 이미지 width는 화면 사이즈 만큼 늘어나고 height 그에 맞게 설정이 됩니다. 참고하세요. 더보기
[Android] 이미지 크기 알아보는 방법 /** Get Bitmap's Width **/ public static int getBitmapOfWidth( String fileName ){ try { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(fileName, options); return options.outWidth; } catch(Exception e) { return 0; } } /** Get Bitmap's height **/ public static int getBitmapOfHeight( String fileName ){ try { BitmapFactory.Opt.. 더보기
[Android] 화면 전체 사이즈 구하기 아래 함수를 호출 한다.public Point getScreenSize(Activity activity) { Display display = activity.getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); return size; } 위 상태에서 width : size.x height : size.y 값을 이용하면 된다. Library나 예제 소스에 간혹 아래와 같이 호출을 하는데 int screenHeight = parentLayout.getRootView() .getHeight();위와 같은 방법을 쓰면 최신 버전에서 전혀 다른 값이 나올 수 있다.예를 들어 제가 Nexus4 로 테스트 해본 .. 더보기
[Android] ResizableImageView ImageView 에서 width를 화면으로 가득 채우고, 해당 Image에 따라 Height를 조절하고자 할 경우,ImageView의 scaleType만으론 표현이 불가능하다. 이럴 경우 아래와 같이 ImageView를 커스텀화 해서 사용하자. public class ResizableImageView extends ImageView { public ResizableImageView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){ Drawable d = getDrawable(); if(d!=nul.. 더보기
[Android] RecyclerView 에서 각 View 크기 조절 RecyclerView 에서 동적으로 Layout을 바꾸고 싶을 경우 아래와 같이 수정해보세요.View의 width 와 height를 같게 만드는 소스 이다. ## onBindViewHolder 함수 내에서GridLayoutManager.LayoutParams layoutParams = (GridLayoutManager.LayoutParams)viewHolder.itemView.getLayoutParams(); layoutParams.height = layoutParams.width; viewHolder.itemView.requestLayout(); RecyclerView에서 설정한 LayoutManager에서 사용하는 LayoutParams를 가져 온후, 수정하면 된다. 참고 하세요. 더보기
[Android] View 위치 및 사이즈 알아 내기 (전체 레이아웃 View).getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { // 여기 에서 찾고 하는 View의 사이즈와 위치 함수를 호출 하면 됩니다. } }); ## 이블로그는 어디까지는 찾았던 부분을 잊지 않기 위해 올려놓은 것 입니다. 내용이 부실해도 이해해 주시길 바랍니다. 더보기
[Android] ImageView 사이즈 ViewTreeObserver vto = image1.getViewTreeObserver(); vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { public boolean onPreDraw() { image1.getViewTreeObserver().removeOnPreDrawListener(this); Log.e(getClass().getName(),"imageView size : Height: " + image1.getMeasuredHeight() + " Width: " + image1.getMeasuredWidth()); return true; } }); 위 방법을 통하면 ImageVIew 사이즈를 구할수있다. 더보기
[ Android ] Offset까지 포함한 전체 사이즈 구하기. 제가 LiveWallpaper를 개발을 많이 해서 화면의 Offset을 자주 이용하는데요. 요새 화면이 너무 제각각이고, 더 짜증나는게 Offset의 사이즈도 제각각이 되어버렸네요;; 전에 핸드폰으로 할 때에는 540을 더해줘서 생각해주면 문제가 없었는데.. 이제는 패드.. 7.5인치 핸드폰 등등... 정말 죽을 맛이죠;; 결국 구글링을 해본 결과!!! Offset까지 포함한 Width와 Height 사이즈를 구하는 방법을 찾았습니다. 한 시간 정도? 찾았나... 역시 간단하게 제공하더라구요. WallpaperManager wm = WallpaperManager.getInstance(mContext); wm.getDesiredMinimumWidth(); 위 함수의 리턴 값이 바로! 저희들이 원하는 값입니.. 더보기