title: How can I move an image and scale or resize it in the same activity
body: <p>how's it going?  I was wondering if anyone had any ideas on how to move an image and resize it within the same activity? I setup a listener to move the image and that works well. The commented out code was used to resize the image and that worked well also. But I am struggling to figure out how to implement some kind of GestureDetector or something similar to do both. Here is the code I have so far:</p>
  
  <pre><code>
      private static final String TAG = "CreateOutfitActivity";
  
      Context mContext;
  
      ImageView bodyImage, outfitOne, close;
      Button saveButton;
      RecyclerView recyclerView;
      Spinner spinner;
  
      FirebaseAuth mAuth;
      String currentUserID;
      DatabaseReference privateUserReference;
      String CategoryKey;
  
      List&lt;String&gt; spinnerArray = new ArrayList&lt;&gt;();
      private ScaleGestureDetector scaleGestureDetector;
  
      ViewGroup rootLayout;
      private int _xDelta;
      private int _yDelta;
  
      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_create_outfits);
          mContext = CreateOutfitActivity.this;
  
          deployWidgets();
          setupRecyclerView();
          setupFirebase();
          setupSpinner();
  
      }
  
      private void deployWidgets(){
          bodyImage = findViewById(R.id.bodyimage);
          outfitOne = findViewById(R.id.image_view_one);
          close = findViewById(R.id.close);
          saveButton = findViewById(R.id.saveButton);
          recyclerView = findViewById(R.id.outfit_recycler_view);
          spinner = findViewById(R.id.spinner);
  
          outfitOne.bringToFront();
  
          rootLayout = findViewById(R.id.view_root);
          RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(1000, 1000);
          outfitOne.setLayoutParams(layoutParams);
          outfitOne.setOnTouchListener(new ChoiceTouchListener());
  
      }
  
      private void setupRecyclerView(){
          recyclerView.setHasFixedSize(true);
          LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
          recyclerView.setLayoutManager(linearLayoutManager);
      }
  
      private void setupFirebase(){
          mAuth = FirebaseAuth.getInstance();
          currentUserID = mAuth.getCurrentUser().getUid();
          privateUserReference = FirebaseDatabase.getInstance().getReference().child("private_user");
      }
  
      private void setupSpinner(){
          spinnerArray.add("Cutouts");
          spinnerArray.add("All Items");
          spinnerArray.add("Accessories");
          spinnerArray.add("Athletic");
          spinnerArray.add("Casual");
          spinnerArray.add("Dresses");
          spinnerArray.add("Jackets");
          spinnerArray.add("Jewelery");
          spinnerArray.add("Other");
          spinnerArray.add("Pants");
          spinnerArray.add("Purses");
          spinnerArray.add("Shirts");
          spinnerArray.add("Shoes");
          spinnerArray.add("Shorts");
          spinnerArray.add("Suits");
  
          ArrayAdapter&lt;String&gt; arrayAdapter = new ArrayAdapter&lt;String&gt;(mContext, android.R.layout.simple_spinner_item, spinnerArray);
          arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spinner.setAdapter(arrayAdapter);
  
          spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
              @Override
              public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                  String text = spinner.getItemAtPosition(position).toString().toLowerCase();
                  CategoryKey = text;
                  if (position == 1){
                      CategoryKey = text.replace("All Items", "all_items");
                  }
  //                if (text.equals("All Items")){
  //
  //                }
                  queryFirebaseToDisplayCategory(CategoryKey);
              }
  
              @Override
              public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
              }
          });
  
      }
  
      private void queryFirebaseToDisplayCategory(String CategoryKey){
  
          Query query = privateUserReference.child(currentUserID).child(CategoryKey).orderByKey();
          FirebaseRecyclerOptions&lt;Category&gt; firebaseRecyclerOptions =
                  new FirebaseRecyclerOptions.Builder&lt;Category&gt;().setQuery(query, Category.class).build();
          FirebaseRecyclerAdapter&lt;Category, OutfitViewHolder&gt; firebaseRecyclerAdapter =
                  new FirebaseRecyclerAdapter&lt;Category, OutfitViewHolder&gt;(firebaseRecyclerOptions) {
                      @Override
                      protected void onBindViewHolder(@NonNull OutfitViewHolder outfitViewHolder, int i, @NonNull Category category) {
  
                          String PostKey = getRef(i).getKey();
  
                          Picasso.get().load(category.getFile_uri()).into(outfitViewHolder.recyclerImage);
                          outfitViewHolder.mView.setOnClickListener(new View.OnClickListener() {
                              @Override
                              public void onClick(View v) {
                                  privateUserReference.child(currentUserID).child(CategoryKey).child(PostKey)
                                          .addValueEventListener(new ValueEventListener() {
                                      @Override
                                      public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                                          String fileURI = dataSnapshot.child("file_uri").getValue().toString();
                                          displayRecyclerImage(fileURI);
                                      }
  
                                      @Override
                                      public void onCancelled(@NonNull DatabaseError databaseError) {
  
                                      }
                                  });
                              }
                          });
                      }
  
                      @NonNull
                      @Override
                      public OutfitViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                          View view = LayoutInflater.from(mContext).inflate(R.layout.layout_outfit_item_view, parent, false);
                          return new OutfitViewHolder(view);
                      }
                  };
          firebaseRecyclerAdapter.startListening();
          recyclerView.setAdapter(firebaseRecyclerAdapter);
      }
  
      private void displayRecyclerImage(String fileURI){
          if (fileURI != null){
              Picasso.get().load(fileURI).into(outfitOne);
          }
      }
  
      public class OutfitViewHolder extends RecyclerView.ViewHolder{
  
          View mView = itemView;
          ImageView recyclerImage;
  
          public OutfitViewHolder(@NonNull View itemView) {
              super(itemView);
  
              recyclerImage = mView.findViewById(R.id.outfit_recycler_image);
          }
      }
  
      private final class ChoiceTouchListener implements View.OnTouchListener {
  
          public boolean onTouch(View view, MotionEvent event){
              final int X = (int) event.getRawX();
              final int Y = (int) event.getRawY();
              switch (event.getAction() &amp; MotionEvent.ACTION_MASK){
                  case MotionEvent.ACTION_DOWN:
                      RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams)view.getLayoutParams();
                      _xDelta = X - lParams.leftMargin;
                      _yDelta = Y - lParams.topMargin;
                      break;
                  case MotionEvent.ACTION_UP:
                      break;
                  case MotionEvent.ACTION_POINTER_DOWN:
                      break;
                  case MotionEvent.ACTION_POINTER_UP:
                      break;
                  case MotionEvent.ACTION_MOVE:
                      RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)view.getLayoutParams();
                      layoutParams.leftMargin = X - _xDelta;
                      layoutParams.topMargin = Y - _yDelta;
                      layoutParams.rightMargin = -0;
                      layoutParams.bottomMargin = -0;
                      view.setLayoutParams(layoutParams);
                      break;
              }
              rootLayout.invalidate();
              return true;
          }
  
      }
  
      private class MySimpleOnScaleGestureListener
              extends ScaleGestureDetector.SimpleOnScaleGestureListener{
  
          ImageView viewMyImage;
  
          float factor;
  
          public MySimpleOnScaleGestureListener(ImageView iv) {
              super();
              viewMyImage = iv;
              factor = 1.0f;
          }
  
          @Override
          public boolean onScale(ScaleGestureDetector detector) {
  
              float scaleFactor = detector.getScaleFactor() - 1;
              factor += scaleFactor;
              viewMyImage.setScaleX(factor);
              viewMyImage.setScaleY(factor);
              return true;
              //return super.onScale(detector);
          }
      }
  }```
  
  
  </code></pre>