I am trying to make a Custom RelativeLayout that can scale and scroll. Right now I was trying to achieve scale. Now I have created a custom Relative layout as the parent layout of another relative layout that contains the touch Imageview as its child. Now, when I enlarge the parent custom relative layout, the child also gets the zoom, but the area that you can click on the image is translated, I donβt know why? When the image or layout is in its normal position, the clickable area is in the image viewer, but as soon as the layout expands, do the shifted areas shift? I donβt know why I am faced with moving the shifted position of the clicked
here is the code
my usual relative layourt
public class scaleLayout extends RelativeLayout { private float mScaleFactor=1.0f; private long lastTouchTime = -1; public scaleLayout(Context context) { super(context);
here is the action
public class LayoutZoomingActivity extends Activity implements OnTouchListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView img1 = (ImageView) findViewById(R.id.imageView1); img1.setOnTouchListener(this); ImageView img2 = (ImageView) findViewById(R.id.imageView2); img2.setOnTouchListener(this); } @Override public boolean onTouch(View v, MotionEvent event) {
this is xml
<com.layoutzooming.scaleLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/gm01" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="jhkibnkij" android:layout_centerInParent="true" android:textColor="#FFFFFF" android:textSize="25dp" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_marginLeft="500dp" android:layout_marginTop="250dp" android:background="#000" android:src="@drawable/dih01" /> <ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_marginLeft="350dp" android:layout_marginTop="250dp" android:background="#000" android:src="@drawable/dih02" /> </RelativeLayout> </com.layoutzooming.scaleLayout>
source share