본문 바로가기

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] Recycler View 사이에 divider 크기 조절 RecyclerView는 각 Row에 Decoration을 줄 수가 있습니다. 이때 사용하는 클래스가 RecyclerView.ItemDecoration 입니다. 간단하게 리스트 사이에 간격을 별려주는 소스 입니다. public class CustomRecyclerDecoration extends RecyclerView.ItemDecoration { private final int divHeight; public CustomRecyclerDecoration(int divHeight) { this.divHeight = divHeight; } @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerVie.. 더보기
[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 사이즈를 구할수있다. 더보기