List of usage examples for android.widget RelativeLayout measure
public final void measure(int widthMeasureSpec, int heightMeasureSpec)
This is called to find out how big a view should be.
From source file:com.shalzz.attendance.fragment.AttendanceListFragment.java
@Override public void onItemExpanded(final View view) { final int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); final ExpandableListAdapter.GenericViewHolder viewHolder = (ExpandableListAdapter.GenericViewHolder) view .getTag();//from w w w . j a v a 2 s.c o m final RelativeLayout childView = viewHolder.childView; childView.measure(spec, spec); final int startingHeight = view.getHeight(); final ViewTreeObserver observer = mRecyclerView.getViewTreeObserver(); observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { // We don'mTracker want to continue getting called for every draw. if (observer.isAlive()) { observer.removeOnPreDrawListener(this); } // Calculate some values to help with the animation. final int endingHeight = view.getHeight(); final int distance = Math.abs(endingHeight - startingHeight); final int baseHeight = Math.min(endingHeight, startingHeight); final boolean isExpanded = endingHeight > startingHeight; // Set the views back to the start state of the animation view.getLayoutParams().height = startingHeight; if (!isExpanded) { viewHolder.childView.setVisibility(View.VISIBLE); } // Set up the fade effect for the action buttons. if (isExpanded) { // Start the fade in after the expansion has partly completed, otherwise it // will be mostly over before the expansion completes. viewHolder.childView.setAlpha(0f); viewHolder.childView.animate().alpha(1f).setStartDelay(mFadeInStartDelay) .setDuration(mFadeInDuration).start(); } else { viewHolder.childView.setAlpha(1f); viewHolder.childView.animate().alpha(0f).setDuration(mFadeOutDuration).start(); } view.requestLayout(); // Set up the animator to animate the expansion and shadow depth. ValueAnimator animator = isExpanded ? ValueAnimator.ofFloat(0f, 1f) : ValueAnimator.ofFloat(1f, 0f); // scroll to make the view fully visible. mRecyclerView.smoothScrollToPosition(viewHolder.position); animator.addUpdateListener(animator1 -> { Float value = (Float) animator1.getAnimatedValue(); // For each value from 0 to 1, animate the various parts of the layout. view.getLayoutParams().height = (int) (value * distance + baseHeight); float z = mExpandedItemTranslationZ * value; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { view.setTranslationZ(z); } view.requestLayout(); }); // Set everything to their final values when the animation's done. animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; if (!isExpanded) { viewHolder.childView.setVisibility(View.GONE); } else { // This seems like it should be unnecessary, but without this, after // navigating out of the activity and then back, the action view alpha // is defaulting to the value (0) at the start of the expand animation. viewHolder.childView.setAlpha(1); } } }); animator.setDuration(mExpandCollapseDuration); animator.start(); // Return false so this draw does not occur to prevent the final frame from // being drawn for the single frame before the animations start. return false; } }); }
From source file:de.tum.frm2.nicos_android.gui.MainActivity.java
private void setPanelHeight(boolean withButtonsVisible) { int panelHeight = 0; RelativeLayout currentDeviceLayout = (RelativeLayout) findViewById(R.id.currentDeviceView); currentDeviceLayout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); panelHeight += currentDeviceLayout.getMeasuredHeight(); if (withButtonsVisible) { RelativeLayout smallButtonsLayout = (RelativeLayout) findViewById(R.id.layoutSmallButtons); smallButtonsLayout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); panelHeight += smallButtonsLayout.getMeasuredHeight(); }//from w w w .j av a 2 s .co m _slidingUpPanelLayout.setPanelHeight(panelHeight); }
From source file:cl.ipp.katbag.fragment.Player.java
public Bitmap createBitmapFromRelativeLayout(RelativeLayout view) { view.setLayoutParams(new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);/*ww w . j a v a 2 s . c o m*/ Canvas c = new Canvas(bitmap); view.draw(c); return bitmap; }
From source file:com.mobileman.moments.android.frontend.fragments.StreamListFragment.java
private void doIt() { // View v = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.overlay_thumbnail, null, false); /* Bitmap overlayBitmap = Bitmap.createBitmap(getResources().getDimensionPixelOffset(R.dimen.thumbnailWidth), getResources().getDimensionPixelOffset(R.dimen.thumbnailHeight),Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(overlayBitmap); Drawable bgDrawable = overlayView.getBackground(); if (bgDrawable!=null)//from w w w . ja v a2s . co m bgDrawable.draw(canvas); else canvas.drawColor(Color.WHITE); overlayView.draw(canvas); */ LayoutInflater mInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); //Inflate the layout into a view and configure it the way you like RelativeLayout view = new RelativeLayout(getActivity()); mInflater.inflate(R.layout.overlay_thumbnail, view, true); // TextView tv = (TextView) findViewById(R.id.my_text); // tv.setText("Beat It!!"); //Provide it with a layout params. It should necessarily be wrapping the //content as we not really going to have a parent for it. view.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); //Pre-measure the view so that height and width don't remain null. view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); //Assign a size and position to the view and all of its descendants view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); //Create the bitmap Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888); //Create a canvas with the specified bitmap to draw into Canvas c = new Canvas(bitmap); //Render this view (and all of its children) to the given Canvas view.draw(c); String path = Environment.getExternalStorageDirectory().toString(); OutputStream fOut = null; File file = new File(path, "testing.jpg"); // the File to save to try { fOut = new FileOutputStream(file); } catch (FileNotFoundException e) { e.printStackTrace(); } bitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut); // saving the Bitmap to a file compressed as a JPEG with 85% compression rate try { fOut.flush(); } catch (IOException e) { e.printStackTrace(); } finally { try { fOut.close(); // do not forget to close the stream } catch (IOException e) { e.printStackTrace(); } } }
From source file:ch.uzh.supersede.feedbacklibrary.AnnotateImageActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); // In both cases whether the action is accepted or cancelled, the temporary stored files need to be deleted List<File> tempFiles = annotateImageView.getCroppedImageLists(); for (int i = 1; i < tempFiles.size(); ++i) { tempFiles.get(i).delete();/* ww w . ja v a 2s. c o m*/ } tempFiles.clear(); if (id == R.id.supersede_feedbacklibrary_action_annotate_cancel) { super.onBackPressed(); return true; } if (id == R.id.supersede_feedbacklibrary_action_annotate_accept) { RelativeLayout relativeLayout = (RelativeLayout) findViewById( R.id.supersede_feedbacklibrary_annotate_image_layout); if (relativeLayout != null) { // Remove all the annotation which are out of bounds removeOutOfBoundsAnnotations(); // Hide all control items hideAllControlItems(relativeLayout); // Process all the sticker annotations HashMap<Integer, String> allStickerAnnotations = processStickerAnnotations(relativeLayout); // Process all the text annotations HashMap<Integer, String> allTextAnnotations = processTextAnnotations(relativeLayout); String annotatedImagePathWithoutStickers = null; if (allStickerAnnotations.size() > 0 || allTextAnnotations.size() > 0) { // Get the bitmap (image without stickers if there are any) Bitmap annotatedBitmapWithoutStickers = annotateImageView.getBitmap(); annotatedImagePathWithoutStickers = Utils.saveBitmapToInternalStorage(getApplicationContext(), "imageDir", mechanismViewId + FeedbackActivity.ANNOTATED_IMAGE_NAME_WITHOUT_STICKERS, annotatedBitmapWithoutStickers, Context.MODE_PRIVATE, Bitmap.CompressFormat.PNG, 100); } // Convert the ViewGroup, i.e., the supersede_feedbacklibrary_annotate_picture_layout into a bitmap (image with stickers) relativeLayout.measure( View.MeasureSpec.makeMeasureSpec(annotateImageView.getBitmapWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(annotateImageView.getBitmapHeight(), View.MeasureSpec.EXACTLY)); relativeLayout.layout(0, 0, relativeLayout.getMeasuredWidth(), relativeLayout.getMeasuredHeight()); Bitmap annotatedBitmapWithStickers = Bitmap.createBitmap(relativeLayout.getLayoutParams().width, relativeLayout.getLayoutParams().height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(annotatedBitmapWithStickers); relativeLayout.draw(canvas); Bitmap croppedBitmap = Bitmap.createBitmap(annotatedBitmapWithStickers, 0, 0, annotateImageView.getBitmapWidth(), annotateImageView.getBitmapHeight()); String annotatedImagePathWithStickers = Utils.saveBitmapToInternalStorage(getApplicationContext(), "imageDir", mechanismViewId + FeedbackActivity.ANNOTATED_IMAGE_NAME_WITH_STICKERS, croppedBitmap, Context.MODE_PRIVATE, Bitmap.CompressFormat.PNG, 100); Intent intent = new Intent(); intent.putExtra(Utils.EXTRA_KEY_MECHANISM_VIEW_ID, mechanismViewId); intent.putExtra(Utils.EXTRA_KEY_ANNOTATED_IMAGE_PATH_WITHOUT_STICKERS, annotatedImagePathWithoutStickers); intent.putExtra(Utils.EXTRA_KEY_ANNOTATED_IMAGE_PATH_WITH_STICKERS, annotatedImagePathWithStickers); intent.putExtra(Utils.EXTRA_KEY_HAS_STICKER_ANNOTATIONS, allStickerAnnotations.size() > 0); intent.putExtra(Utils.EXTRA_KEY_ALL_STICKER_ANNOTATIONS, allStickerAnnotations); intent.putExtra(Utils.EXTRA_KEY_HAS_TEXT_ANNOTATIONS, allTextAnnotations.size() > 0); intent.putExtra(Utils.EXTRA_KEY_ALL_TEXT_ANNOTATIONS, allTextAnnotations); setResult(RESULT_OK, intent); } super.onBackPressed(); return true; } return super.onOptionsItemSelected(item); }