项目布局
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/top_panel"
android:background="@drawable/transback"
app:cardCornerRadius="10dp"
android:layout_marginBottom="1dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp">
<ImageView
android:id="@+id/categoryImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY" />
</android.support.v7.widget.CardView>
我想像这样设置图像大小正方形 屏幕宽度 = 图片高度
这是我用于回收站查看的项目
这怎么可能……?
最佳答案
可以自定义ImageView
来创建SquareImageView
public class SquareImageView extends ImageView {
public SquareImageView(Context context) {
super(context);
}
public SquareImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getMeasuredWidth();
setMeasuredDimension(width, width);
}
}
关于java - 如何设置图片大小正方形.. 所有手机屏幕都支持哪些?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55256841/