用典型shape来当背景,linearlayout套住imageview,本来用的padding,结果导致长宽padding的距离不一样,非常难看,原来直接用margin就可以了。
<LinearLayout
android:id="@+id/linear_studentphoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape_photo_bg" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:scaleType="centerCrop"
android:src="@mipmap/baobao"
android:id="@+id/student_photo" />
</LinearLayout>
shape里面的代码很简单,drawable里面建一个
shape_photo_bg.xml,
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:color="@color/huang"
android:width="15dp"/>
<corners android:radius="10dp"/>
<solid android:color="@color/huang"/>
</shape>
代码里面引用图片直接设置 外层linearlayout的布局参数就可以了,imageview只需要设置内容即可。
student_photo = (ImageView) view.findViewById(R.id.student_photo);
linear_studentphoto = (LinearLayout) view.findViewById(R.id.linear_studentphoto);
int photokuan = 70;
int photogao = 100;
linear_studentphoto.setLayoutParams(new LinearLayout.LayoutParams(photokuan, photogao));
转载请注明原文地址: https://ju.6miu.com/read-676882.html