How to check which current image resource is attached to ImageView in android xml?

Hi please have a try with this as follows if (regProfile.getDrawable().getConstantState() == getResources().getDrawable( R.drawable.ivpic).getConstantState()) { Toast.makeText(_con, “Image is ivPic”, Toast.LENGTH_LONG).show(); // new RegisterAsyntaskNew().execute(); } else { Toast.makeText(_con, “Image isn’t ivPic”, Toast.LENGTH_LONG).show(); // new RegisterAsyntask().execute(); } please use .getConstantState() to compare visit http://developer.android.com/reference/android/graphics/drawable/Drawable.html http://developer.android.com/reference/android/graphics/drawable/Drawable.ConstantState.html EDIT: .getResources().getDrawable(imageResource) Is deprecated in API21, so I changed Jitesh Upadhyay’s answer. … Read more

Add gradient to imageview

You need two layers: An ImageView, and a View on top of that with your gradient as android:background. Put these two Views in a FrameLayout: <FrameLayout … > <ImageView … android:src=”https://stackoverflow.com/questions/23991395/@drawable/trend_donald_sterling” /> <View … android:background=”https://stackoverflow.com/questions/23991395/@drawable/trending_gradient_shape”/> </FrameLayout>

Android Image Dialog/Popup

No xml: public void showImage() { Dialog builder = new Dialog(this); builder.requestWindowFeature(Window.FEATURE_NO_TITLE); builder.getWindow().setBackgroundDrawable( new ColorDrawable(android.graphics.Color.TRANSPARENT)); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { //nothing; } }); ImageView imageView = new ImageView(this); imageView.setImageURI(imageUri); builder.addContentView(imageView, new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); builder.show(); }

When it’s necessary to execute invalidate() on a View?

(Do consider accepting some answers) Generally, invalidate() means ‘redraw on screen’ and results to a call of the view’s onDraw() method. So if something changes and it needs to be reflected on screen, you need to call invalidate(). However, for built-in widgets you rarely, if ever, need to call it yourself. When you change the … Read more

Show ImageView programmatically

//LinearLayOut Setup LinearLayout linearLayout= new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); //ImageView Setup ImageView imageView = new ImageView(this); //setting image resource imageView.setImageResource(R.drawable.play); //setting image position imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); //adding view to layout linearLayout.addView(imageView); //make visible to program setContentView(linearLayout);

Get the ID of a drawable in ImageView

I think if I understand correctly this is what you are doing. ImageView view = (ImageView) findViewById(R.id.someImage); view.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { ImageView imageView = (ImageView) view; assert(R.id.someImage == imageView.getId()); switch(getDrawableId(imageView)) { case R.drawable.foo: imageView.setDrawableResource(R.drawable.bar); break; case R.drawable.bar: default: imageView.setDrawableResource(R.drawable.foo); break; } }); Right? So that function getDrawableId() doesn’t exist. You … Read more

Android ImageView: Fit Width

I ended up using this code: <ImageView android:id=”@+id/background” android:layout_width=”match_parent” android:layout_height=”match_parent” android:adjustViewBounds=”true” android:scaleType=”centerCrop” android:src=”https://stackoverflow.com/questions/12059328/@drawable/name” /> Make sure you set the image using src instead of background.