I am using translationZ to put a imageview on top of a relative layout. But it seems android:translationZ="2dp" is not working below api level 21. Whats the alternative for this ?
PFB code :
RelativeLayout layout_main = (RelativeLayout) findViewById(R.id.layout_main);
ImageView myimage= (ImageView) view.findViewById(R.id.myimage);
Picasso.with(getContext()).load("image url")
.error(getContext().getResources().getDrawable(R.mipmap.ic_business_black_48dp))
.resize(200,200).centerInside()
.placeholder(getContext().getResources().getDrawable(R.mipmap.ic_business_black_48dp)).into(myimage);
layout_main.bringToFront();
<RelativeLayout
android:id="@+id/layout_main"
android:layout_width="90dip"
android:layout_height="90dip"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:background="#ededeb"
android:translationZ="3dp"
android:elevation="20dp">
<ImageView
android:id="@+id/myimage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:src="@mipmap/ic_business_black_48dp" />
</RelativeLayout>
You can ask to bring it to front (similar to How to bring view on front of everything?), use View.bringToFront()
, but this will not render a shadow for you. Earlier OS versions don't have native support for shadows so you would need to work around it if you do desperately need it.
API 21 has view.setElevation(float)
build-in
Use ViewCompat.setElevation(view, float);
for backward compatibility
More methods ViewCompat.setZ(v, pixels)
and ViewCompat.setTranslationZ(v, pixels)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With