How to get the Dimensions of a Drawable in an ImageView? [duplicate]

Just tried this out and it works for me: int finalHeight, finalWidth; final ImageView iv = (ImageView)findViewById(R.id.scaled_image); final TextView tv = (TextView)findViewById(R.id.size_label); ViewTreeObserver vto = iv.getViewTreeObserver(); vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { public boolean onPreDraw() { // Remove after the first run so it doesn’t fire forever iv.getViewTreeObserver().removeOnPreDrawListener(this); finalHeight = iv.getMeasuredHeight(); finalWidth = iv.getMeasuredWidth(); tv.setText(“Height: ” + finalHeight … Read more

Set visibility of progress bar gone on completion of image loading using Glide library

Question is rather old, and I don’t know what was the situation with glide in those times, but now it can be easily done with listener (not as proposed in the answer chosen as correct). progressBar.setVisibility(View.VISIBLE); Glide.with(getActivity()) .load(args.getString(IMAGE_TO_SHOW)) .listener(new RequestListener<String, GlideDrawable>() { @Override public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { return … Read more

Android how to identify item in listview with checkbox

This is XML for Custom Row in ListView : <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”fill_parent”> <ImageView android:id=”@+id/imageView1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:src=”https://stackoverflow.com/questions/9444165/@drawable/camera_icon” /> <TextView android:id=”@+id/textView1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Large Text” android:textAppearance=”?android:attr/textAppearanceLarge” /> <CheckBox android:id=”@+id/checkBox1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”” /> </LinearLayout> This is Complete Activity in which List is implemented : Just Copy this Activity for test then understand … Read more

Android image view matrix scale + translate

There’s a convenient method called Matrix.setRectToRect(RectF, RectF, ScaleToFit) to help you here. Matrix m = imageView.getImageMatrix(); RectF drawableRect = new RectF(0, 0, imageWidth, imageHeight); RectF viewRect = new RectF(0, 0, imageView.getWidth(), imageView.getHeight()); m.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.CENTER); imageView.setImageMatrix(m); That should set the matrix m to have combo of scaling and translate values that is needed to show … Read more

Android Drag and drop images on the Screen?

Write Below Code into your Activity File. windowwidth = getWindowManager().getDefaultDisplay().getWidth(); windowheight = getWindowManager().getDefaultDisplay().getHeight(); tv1 = (ImageView)findViewById(R.id.image); tv1.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { layoutParams1 = (RelativeLayout.LayoutParams) tv1.getLayoutParams(); switch(event.getActionMasked()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_MOVE: int x_cord = (int) event.getRawX(); int y_cord = (int) event.getRawY(); if (x_cord > windowwidth) { x_cord = … Read more

Full screen background image in an activity

There are several ways you can do it. Option 1: Create different perfect images for different dpi and place them in related drawable folder. Then set android:background=”https://stackoverflow.com/questions/16135984/@drawable/your_image” Option 2: Add a single large image. Use FrameLayout. As a first child add an ImageView. Set the following in your ImageView. android:src=”https://stackoverflow.com/questions/16135984/@drawable/your_image” android:scaleType = “centerCrop”