Open top menu

 Example :- How to drag and drop imageView,textVew programmatically in android.

First ,you have to Used Library Sticker View,with help of stickerView you can rotate and scale Image and text.

activity_main.xml


xml version="1.0" encoding="utf-8"?>

<FrameLayout
   
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:id="@+id/canvasView"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
tools:context=".MainActivity">


    <
ImageView
       
android:id="@+id/imageView"
       
android:layout_gravity="center"
       
android:layout_width="wrap_content"
        
android:layout_height="wrap_content"
       
android:src="@drawable/im"
       
android:scaleType="fitXY"/>
</
FrameLayout>


MainActivity.java

package com.project.example.draganddropproject;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.FrameLayout;

public class MainActivity extends AppCompatActivity {

   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);

        setContentView(R.layout.
activity_main);

        FrameLayout canvas = (FrameLayout) findViewById(R.id.
canvasView);

       
//add a stickerImage to canvas
       
StickerImageView iv_sticker = new StickerImageView(MainActivity.this);
        iv_sticker.setImageDrawable(getResources().getDrawable(R.drawable.
cap));
        canvas.addView(iv_sticker);

       
//add a stickerText to canvas
       
StickerTextView tv_sticker = new StickerTextView(MainActivity.this);
        tv_sticker.setText(
"Android Tutorial Point");
        canvas.addView(tv_sticker);

    }
}





0 comments