如何在按钮单击时添加两个imageview并显示为单个图像

时间:2017-06-04 20:26:42

标签: java android xml android-layout imageview

我需要将这些图像视图组合并显示为新的图像视图

我尝试合并两个图像视图,但图像没有合并为单个图像。

此图像应为框架,另一图像应位于空白区域

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    collageImage = (ImageView)findViewById(R.id.center);
    Button combineImage = (Button)findViewById(R.id.Btn_comineimage);
    combineImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            bigImage = BitmapFactory.decodeResource(getResources(), R.drawable.multiple);
            smallImage = BitmapFactory.decodeResource(getResources(), R.drawable.multipletwo);
            mergeimage();//merge and display on click.



        }
    });


}

public void mergeimage()
{
    //need code for combining both image to one and setimagebitmap to collageimage.

}

main.xml中

这里我附上了我的xml编码供您参考。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/Main_layout"
tools:context="com.imagemerge.albin.imagemerge.MainActivity">
<ImageView
android:id="@+id/base"
android:layout_height="200dp"
android:layout_width="200dp"
android:src="@drawable/multiple"
android:scaleType="fitXY"
android:layout_alignTop="@+id/center"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:id="@+id/center"
android:layout_height="180dp"
android:layout_width="85dp"
android:src="@drawable/multipletwo"
android:layout_marginLeft="230dp"
android:layout_marginTop="15dp"
android:scaleType="fitXY"/>
<Button
android:id="@+id/Btn_comineimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/center"
android:layout_alignRight="@+id/center"
android:layout_below="@+id/base"
android:layout_marginEnd="89dp"
android:layout_marginRight="89dp"
android:layout_marginTop="10dp"
android:text="Merge" />
<ImageView
android:id="@+id/Mergedimage"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_below="@+id/Btn_comineimage"
android:layout_marginLeft="100dp"
android:background="@color/colorAccent"
android:scaleType="fitXY"
android:layout_marginTop="10dp"
/>
</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

您可以使用FrameLayout。请查看以下链接了解更多详情:

https://developer.android.com/reference/android/widget/FrameLayout.html

使用FrameLayout,您可以在其他元素上添加一个元素。

相关问题