gpt4 book ai didi

java - 如何更改以编程方式添加的图像大小

转载 作者:行者123 更新时间:2023-11-30 00:45:03 26 4
gpt4 key购买 nike

我有一个 LinearLayout,当我点击一个按钮时我会添加图像,我试图使用 LayoutParams 来改变宽度和高度,因为它不适合应该,而且我总是得到一个空引用,问题是我无法进行任何引用,因为它不是静态 ImageView

这就是我在 LinearLayout 中添加图像的方式:

public void AddNewImages(Context context,Bitmap bitmap){
ImageView img = new ImageView(context);
img.setScaleType(ImageView.ScaleType.FIT_XY);
img.setImageBitmap(bitmap);
linearImages.addView(img);
bitmapArray.add(bitmap);
indexTags++;
}

XML:

<LinearLayout
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<HorizontalScrollView
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:id="@+id/linearImages"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_gravity="center"
android:id="@+id/add_btn"
android:text="Add"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</HorizontalScrollView>

最佳答案

首先你必须找到你在线性布局中添加的 Imageview 并设置大小即

for(int i=0;i<linearImages.getChildCount();i++)
{
ImageView image=(ImageView)linearImages.getChildAt(i);
image.getLayoutParams().height=100;
image.getLayoutParams().width=100;
}

关于java - 如何更改以编程方式添加的图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41952852/

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