android - How to clip ImageView to CardView size in a framelayout -


i have recyclerview item contains cardview @ root. inside cardview have layout height set wrap_content , works fine, want have image fill cardview when visibility set visible. because image lot larger cardview pushes height of cardview down. image width set fill_parent , height set wrap_content.

<android.support.v7.widget.cardview xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:card_view="http://schemas.android.com/apk/res-auto"     xmlns:app="http://schemas.android.com/tools"     android:id="@+id/card_view"     android:layout_gravity="center"     android:layout_width="match_parent"     android:layout_height="wrap_content">      <framelayout         android:id="@+id/main_container"         android:layout_width="fill_parent"         android:layout_height="fill_parent">          <!-- main container -->         <linearlayout             android:id="@+id/main_container"             android:layout_width="match_parent"             android:layout_height="match_parent"             android:layout_weight="1"             android:orientation="vertical">              <!-- omitted content -->          </linearlayout>          <!-- overlay image -->         <imageview             android:id="@+id/completed_image"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:src="@drawable/completed_stamp"             android:scaletype="centercrop"             android:croptopadding="true"             android:adjustviewbounds="true"             android:visibility="gone"/>      </framelayout>  </android.support.v7.widget.cardview> 

i want overlay image clipped main layout , i'm not sure how go it.

the image 800 x 800 , imageview set centercrop.

i have tried:

framelayout.layoutparams layoutparams = maincontainer.getlayoutparams(); imageview.setlayoutparams(layoutparams); imageview.requestlayout(); 

in onbindviewholder

edit

using code in onbindviewholder:

holder.imageview.getlayoutparams().height = holder.cardview.getheight(); 

this works apply resize next occurrence requires in recyclerview list not solution

i've had similar issues before, may want try adding setting croptopadding attribute true in image view. may or may not cut of image out, if profile photo since scale depending on device/screen size/density.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -