用典型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));
android图片设置边框
最新推荐文章于 2024-05-14 11:35:15 发布