【发布时间】:2017-06-16 14:39:13
【问题描述】:
我有一个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>
【问题讨论】:
-
从 linearImages 子中获取图像视图