Android 在低于21的api级别中,translationZ的替代方案是什么
我使用translationZ将imageview放置在相对布局的顶部。但android:translationZ=“2dp”似乎在api级别21以下无法工作。有什么选择 PFB代码:Android 在低于21的api级别中,translationZ的替代方案是什么,android,Android,我使用translationZ将imageview放置在相对布局的顶部。但android:translationZ=“2dp”似乎在api级别21以下无法工作。有什么选择 PFB代码: RelativeLayout layout_main = (RelativeLayout) findViewById(R.id.layout_main); ImageView myimage= (ImageView) view.findViewById(R.id.myimage); Pic
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>
RelativeLayout\u main=(RelativeLayout)findViewById(R.id.layout\u main);
ImageView myimage=(ImageView)view.findViewById(R.id.myimage);
Picasso.with(getContext()).load(“图像url”)
.error(getContext().getResources().getDrawable(R.mipmap.ic\u business\u black\u 48dp))
.resize(200200).centerInside()
.placeholder(getContext().getResources().getDrawable(R.mipmap.ic_business_black_48dp)).into(myimage);
布局图_main.bringToFront();
您可以要求将其放在前面(类似于),使用View.bringToFront()
,但这不会为您渲染阴影。早期的操作系统版本没有对阴影的本机支持,因此如果您非常需要它,您需要解决它。API21内置了view.setElevation(float)
使用ViewCompat.setElevation(视图,浮动)代码>用于向后兼容
更多方法ViewCompat.setZ(v,像素)
和ViewCompat.setTranslationZ(v,像素)
我正在尝试这段代码,但它似乎不适用于毕加索:毕加索.with(getContext()).load(“image url”).error(getContext().getResources().getDrawable(R.mipmap.ic_business_black48dp)).resize(200200).centerInside().placeholder(getContext().getResources().getDrawable(R.mipmap.ic\u business\u black\u 48dp)).into(公司图像);公司形象。布林托夫隆();你能用布局更新你的问题吗?如果您使用的是旧版本,XML的规则是:视图在视图组中越晚(越低),它的Z方向越高。这不起作用,因为setTranslationZ的实现仅支持21及以上版本。这就是工作:ViewCompat.setElevation(View,float)。谢谢你,伙计!