ImageView displaying in layout but not on actual device

I had the same issue, it is only showing in Design tab for Android Studio 2.2. What I did to make it work is to change the automatic key assigned (populated via Drag/Drop ImageView) from app:srcCompat=”https://stackoverflow.com/questions/18251187/@drawable/logo” to android:src=”https://stackoverflow.com/questions/18251187/@drawable/logo” in Text tab to make it appear on both the emulator and the device e.g <ImageView android:layout_width=”wrap_content” … Read more

Bitmap in ImageView with rounded corners

try this one : public class CustomImageView extends ImageView { public static float radius = 18.0f; public CustomImageView(Context context) { super(context); } public CustomImageView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onDraw(Canvas canvas) { //float radius = 36.0f; Path clipPath … Read more

RecyclerView 2 Columns with CardView

Extracted required info from the accepted answer in case URL becomes invalid in future and to save time. GridLayoutManager is used to display the RecyclerView in Grid manner instead of list. RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(this, 2); recyclerView.setLayoutManager(mLayoutManager); Kotlin version: recyclerView.apply { layoutManager = GridLayoutManager(this, 2) }

Can’t use srcCompat for ImageViews in android

Don’t android:srcCompat=”https://stackoverflow.com/questions/35645148/@drawable/wallpaper” Do app:srcCompat=”https://stackoverflow.com/questions/35645148/@drawable/wallpaper” as it srcCompat attribute is actually defined within AppCompat library. Important you will need to add appropriate namespace for this. xmlns:app=”http://schemas.android.com/apk/res-auto” Important what you are getting it seems like it is just a lint error that can be ignored. I have tried and have the same error, but it is working … Read more

Adding Fling Gesture to an image view – Android

Here’s the simpliest working version of flinger I can think of. You can actually tie it to any component, not only ImageView. public class MyActivity extends Activity { private void onCreate() { final GestureDetector gdt = new GestureDetector(new GestureListener()); final ImageView imageView = (ImageView) findViewById(R.id.image_view); imageView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(final View view, final … Read more

Android: resizing an ImageView in the XML

for example: <ImageView android:id=”@+id/image_view” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:adjustViewBounds=”true” android:maxWidth=”42dp” android:maxHeight=”42dp” android:scaleType=”fitCenter” android:layout_marginLeft=”3dp” android:src=”https://stackoverflow.com/questions/6267733/@drawable/icon” /> Add property android:scaleType=”fitCenter” and android:adjustViewBounds=”true”.

ImageView in android XML layout with layout_height=”wrap_content” has padding top & bottom

I had a simular issue and resolved it using android:adjustViewBounds=”true” on the ImageView. <ImageView android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:adjustViewBounds=”true” android:contentDescription=”@string/banner_alt” android:src=”https://stackoverflow.com/questions/9553913/@drawable/banner_portrait” />