Reputation: 3037
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
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