I have a LinearLayout which I add images when i click a button, I was trying to use LayoutParamsto change the width and height because doesn't fit as at should, and I always got a null reference, the problem is I can't make any reference because is not a static ImageView.
This is how I add images inside of 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>
 
     
     
     
    