1

I am trying to use multiple TouchImageView in one View. Then on single click in TouchImageView picking image from gallery to show in TouchImageView. But the problem is when I set a new Image from gallery in one TouchImageView the other gets also reset means the last zooming is still right of that TouchImageView but the last position of the image inside that gets repositioned.

Here is my code:

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" 
android:orientation="vertical">

<com.example.imagedragpinchtest.TouchImageView 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:id="@+id/TIV1"
    android:src="@drawable/ic_launcher"
    android:background="@drawable/dashline"
    android:layerType="software"
    />
<com.example.imagedragpinchtest.TouchImageView 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:id="@+id/TIV2"
    android:src="@drawable/ic_launcher"
    android:background="@drawable/dashline"
    android:layerType="software"/>
</LinearLayout>

MainActivity.java

package com.example.imagedragpinchtest;
public class MainActivity extends Activity {

TouchImageView tiv1,tiv2;
int selected = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tiv1 = (TouchImageView) findViewById(R.id.TIV1);
    tiv2 = (TouchImageView) findViewById(R.id.TIV2);
    tiv1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            selected = 1;
            Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(intent, selected);
        }
    });
    tiv2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            selected = 2;
            Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(intent, selected);
        }
    });

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode == RESULT_OK){
        String imgPath = getPathFromUri(data.getData());
        Log.e("new", imgPath);
        if(selected == 1)
            tiv1.setImageDrawable(new BitmapDrawable(getResources(), imgPath));
        if(selected == 2)
            tiv2.setImageDrawable(new BitmapDrawable(getResources(), imgPath));
    }

}

public String getPathFromUri(Uri uri) {
    String[] filePathColumn = { MediaStore.Images.Media.DATA };

    Cursor cursor = getContentResolver().query(uri,
            filePathColumn, null, null, null);
    cursor.moveToFirst();

    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    String picturePath = cursor.getString(columnIndex);
    cursor.close();

    return picturePath;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

The library TouchImageView.java

I can't figure out where the problem is, I have also tried by comment out the onSaveInstanceState() and onRestoreInstanceState() of the TouchImageView class. But that also don't solve the problem. Some help will be really appreciable. Thanks in advance.....

Alexander
  • 3,129
  • 2
  • 19
  • 33
Ashiq
  • 430
  • 1
  • 9
  • 24
  • Were you ever able to solve this? – RealCasually Aug 20 '14 at 21:02
  • @RealCasually No, Not with TouchImageView. Later I switched to [MyImageView](http://stackoverflow.com/questions/12169905/zoom-and-panning-imageview-android/12184210#12184210) and modified it according to my specifications. Though it is not good as TouchImageView, as the zooming jumps sometimes..... – Ashiq Aug 21 '14 at 05:17

0 Answers0