user3896501
user3896501

Reputation: 3037

Android - Is it possible to insert an image into another image at specified position?

Example: I got four image with same width and height (e.g. 128px) like: ABCD, then I want to insert another 128x128 image between BC which produce: ABECD, can't figure out how to do that, is it possible?

Upvotes: 1

Views: 383

Answers (1)

cyanide
cyanide

Reputation: 3964

You mean ImageViews or a single image? With ImageViews it's quite straighforward

<LinearLayout
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:orientation="vertical">

   <ImageView
      android:src="@drawable/a"
      android:layout_width="@dimen/imgWidth"
      android:layout_height="@dimen/imgHeight"/>

   <ImageView
      android:src="@drawable/b"
      android:layout_width="@dimen/imgWidth"
      android:layout_height="@dimen/imgHeight"/>

  <ImageView
      android:src="@drawable/c"
      android:layout_width="@dimen/imgWidth"
      android:layout_height="@dimen/imgHeight"/>

  <ImageView
      android:src="@drawable/d"
      android:layout_width="@dimen/imgWidth"
     android:layout_height="@dimen/imgHeight"/>

<LinearLayout>

And your code:

public void insertImage(Activity activity, ViewGroup parent) {
ImageView  iv = new ImageView(activity);
iv.setImageResource(R.drawable.e);
int width = activity.getResources().getDimensionPixelSize(R.dimen.imgWidth));
int height = activity.getResources().getDimensionPixelSize(R.dimen.imgHeight));
parent.addView(iv, 2, new LayoutParams(width, height));
} 

Upvotes: 2

Related Questions