List of usage examples for android.view View getMeasuredHeight
public final int getMeasuredHeight()
From source file:Main.java
public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { // pre-condition return;/* ww w . j a v a2 s . co m*/ } int totalHeight = 0; for (int i = 0; i < listAdapter.getCount(); i++) { View listItem = listAdapter.getView(i, null, listView); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); if (listView.isInLayout() == false) { listView.requestLayout(); } }
From source file:Main.java
public static void getListViewSize(ListView myListView) { ListAdapter myListAdapter = myListView.getAdapter(); if (myListAdapter == null) { //do nothing return null return;//from w ww . j a v a 2s . c o m } //set listAdapter in loop for getting final size int totalHeight = 0; for (int size = 0; size < myListAdapter.getCount(); size++) { View listItem = myListAdapter.getView(size, null, myListView); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } //setting listview item in adapter ViewGroup.LayoutParams params = myListView.getLayoutParams(); params.height = totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1)); myListView.setLayoutParams(params); myListView.requestLayout(); }
From source file:Main.java
public static void getListViewSize(ListView myListView) { ListAdapter myListAdapter = myListView.getAdapter(); if (myListAdapter == null) { //do nothing return null return;/*from ww w. j a v a 2 s .co m*/ } //set listAdapter in loop for getting final size int totalHeight = 0; for (int size = 0; size < myListAdapter.getCount(); size++) { View listItem = myListAdapter.getView(size, null, myListView); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = myListView.getLayoutParams(); params.height = totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1)); myListView.setLayoutParams(params); }
From source file:Main.java
public static void getListViewSize(ListView myListView) { ListAdapter myListAdapter = myListView.getAdapter(); if (myListAdapter == null) { //do nothing return null return;/*from www. j a va 2 s . c o m*/ } //set listAdapter in loop for getting final size int totalHeight = 0; for (int size = 0; size < myListAdapter.getCount(); size++) { View listItem = myListAdapter.getView(size, null, myListView); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } //setting listview item in adapter ViewGroup.LayoutParams params = myListView.getLayoutParams(); params.height = totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1)); myListView.setLayoutParams(params); // print height of adapter on log Log.i("height of listItem:", String.valueOf(totalHeight)); }
From source file:Main.java
private static Bitmap getResizeBitmap(View view, Bitmap bitmap) { Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / sScaleFactor), (int) (view.getMeasuredHeight() / sScaleFactor), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(overlay); canvas.translate(-view.getLeft() / sScaleFactor, -view.getTop() / sScaleFactor); canvas.scale(1 / sScaleFactor, 1 / sScaleFactor); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(bitmap, 0, 0, paint); return overlay; }
From source file:Main.java
public static void prepareViewToGetSize(View view) { view.measure(View.MeasureSpec.makeMeasureSpec(0, 0), View.MeasureSpec.makeMeasureSpec(0, 0)); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); }
From source file:Main.java
public static int getMeasuredHeight(View view) { if (view == null) { throw new IllegalArgumentException("view is null"); }//from w ww . j a va 2s . co m view.measure(0, 0); return view.getMeasuredHeight(); }
From source file:Main.java
public static void animExpand(final View v) { v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); final int targetHeight = v.getMeasuredHeight(); v.getLayoutParams().height = 0;/*from ww w . j av a2s . c o m*/ v.setVisibility(View.VISIBLE); Animation a = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { v.getLayoutParams().height = interpolatedTime == 1 ? LayoutParams.WRAP_CONTENT : (int) (targetHeight * interpolatedTime); v.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; // 1dp/ms a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density)); v.startAnimation(a); }
From source file:Main.java
public static void expand(final View v) { v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); final int targtetHeight = v.getMeasuredHeight(); v.getLayoutParams().height = 0;/*from w ww . j a va 2 s . co m*/ v.setVisibility(View.VISIBLE); Animation a = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { v.getLayoutParams().height = interpolatedTime == 1 ? LayoutParams.WRAP_CONTENT : (int) (targtetHeight * interpolatedTime); v.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; // 1dp/ms a.setDuration((int) (targtetHeight / v.getContext().getResources().getDisplayMetrics().density)); v.startAnimation(a); }
From source file:Main.java
public static void overlay(ListView myListView, LinearLayout.LayoutParams paramsLinearLayout) { ListAdapter myListAdapter = myListView.getAdapter(); if (myListAdapter == null) { //do nothing return null return;/* www . j a v a 2s . c om*/ } //set listAdapter in loop for getting final size int totalHeight = 0; for (int size = 0; size < myListAdapter.getCount(); size++) { View listItem = myListAdapter.getView(size, null, myListView); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } System.out.println("totalHeight :: " + totalHeight); //setting marginTop the next element if (totalHeight > 0) { int marginTop = (totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1))) * -1; paramsLinearLayout.setMargins(0, marginTop, 0, 0); System.out.println("marginTop :: " + marginTop); } else { System.out.println("nada :: totalHeight " + totalHeight); paramsLinearLayout.setMargins(0, 0, 0, 0); } }