gpt4 book ai didi

java - 使用 TouchImageView.java 类查找 TouchImageView 的中心点

转载 作者:太空宇宙 更新时间:2023-11-04 13:39:17 25 4
gpt4 key购买 nike

我有两个 TouchImageView。我想要实现的是,当我从左向右滑动第一个 TouchImageView 时,第二个 TouchImageView 自动从右向左滑动。我正在使用我在 GitHub 上创建的 TouchImageView.java 类。下面是我的代码。

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"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2"
tools:context="com.PinchZoom.pinchzoomexampletwo.MainActivity" >

<com.PinchZoom.pinchzoomexampletwo.TouchImageView
android:id="@+id/img_to_be_zoomed"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_weight="1"
android:src="@drawable/fb" >
</com.PinchZoom.pinchzoomexampletwo.TouchImageView>

<com.PinchZoom.pinchzoomexampletwo.TouchImageView
android:id="@+id/img_to_be_zoomed_mirror"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_weight="1"
android:src="@drawable/fb" >
</com.PinchZoom.pinchzoomexampletwo.TouchImageView>

</LinearLayout>

MainActivity.java

package com.PinchZoom.pinchzoomexampletwo;

import android.graphics.PointF;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;

import com.PinchZoom.pinchzoomexampletwo.TouchImageView.OnTouchImageViewListener;

public class MainActivity extends ActionBarActivity {
TouchImageView img_to_be_zoomed;
TouchImageView img_to_be_zoomed_mirror;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

img_to_be_zoomed = (TouchImageView) findViewById(R.id.img_to_be_zoomed);
img_to_be_zoomed
.setOnTouchImageViewListener(new OnTouchImageViewListener() {

@Override
public void onMove() {

img_to_be_zoomed_mirror.setZoom(img_to_be_zoomed);

Log.e("X Scroll Point: ",
"" + img_to_be_zoomed.getScrollPosition());
}
});

img_to_be_zoomed_mirror = (TouchImageView) findViewById(R.id.img_to_be_zoomed_mirror);
img_to_be_zoomed_mirror
.setOnTouchImageViewListener(new OnTouchImageViewListener() {

@Override
public void onMove() {
// TODO Auto-generated method stub
img_to_be_zoomed.setZoom(img_to_be_zoomed_mirror);
PointF s = new PointF();
PointF q = new PointF();
s = img_to_be_zoomed.getScrollPosition();
q = img_to_be_zoomed_mirror.getScrollPosition();
img_to_be_zoomed.setScrollPosition(s.x
- (q.x - img_to_be_zoomed.getX()), s.y);
Log.e("img_1", s.x + "/" + s.y);
Log.e("img_2", "" + q.x + "/" + q.y);
}
});
}
}

TouchImageView.java

TouchImageView.java Find Here

编辑:我已经在 MainActivity.java 中使用以下代码解决了问题。

PointF pointF_img1 = new PointF();
pointF_img1 = img_to_be_zoomed.getScrollPosition();
img_to_be_zoomed_mirror.setScrollPosition(1 - pointF_img1.x, pointF_img1.y);

最佳答案

我已经在 MainActivity.java 中使用以下代码解决了问题。

PointF pointF_img1 = new PointF();
pointF_img1 = img_to_be_zoomed.getScrollPosition();
img_to_be_zoomed_mirror.setScrollPosition(1 - pointF_img1.x, pointF_img1.y);

关于java - 使用 TouchImageView.java 类查找 TouchImageView 的中心点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31376445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com