gpt4 book ai didi

Android使ShapeDrawable match_parent

转载 作者:行者123 更新时间:2023-11-30 01:55:29 25 4
gpt4 key购买 nike

我正在尝试创建一个彩色圆圈并将其分配给我的 GridView 的 ImageView。

这是我的代码:

ImageView ivColor;

ivColor = new ImageView(MainActivity.this);
ivColor.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

ShapeDrawable shape = new ShapeDrawable(new OvalShape());
shape.getPaint().setColor(color[i]);
shape.setIntrinsicWidth(128);
shape.setIntrinsicHeight(128);

ivColor.setImageDrawable(shape);

现在,我手动将 ShapeDrawable 的高度和宽度设置为 128px。有没有办法像我对 ImageView 所做的那样,为 ShapeDrawable 分配一个“match_parent”值?

最佳答案

尝试换行

ivColor.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 

ivColor.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 

编辑:

此外,设置您必须为 ImageView 运行 setScaleType()

http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

您应该根据需要尝试使用 CENTER_CROPCENTER_FILLFIT_CENTRE

关于Android使ShapeDrawable match_parent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32318331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com