<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.example.canvastest.PanZoomView
android:id="@+id/zoomview"
android:layout_width="300dp"
android:layout_height="300dp" />
<TextView
android:id="@+id/tv_mPosX"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:id="@+id/tv_mPosY"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</LinearLayout>
我想根据在视图中计算的缩放系数(mScaleFactor)来设置tv_mPosX / Y字符串:
public class PanZoomView extends View {
protected Drawable mSampleImage;
protected Context mContext;
protected float mPosX;
protected float mPosY;
//
public float mScaleFactor = 1.f;
...
我在哪里/如何处理?
感谢所有人, 的Riccardo
答案 0 :(得分:0)
mScaleFactor好的伙计们,我找到了解决方案。
1)我在View对象中实现了一个getter
2)这是我的最后一项活动,有一个更新UI的线程
public class MainActivity extends Activity {
private Handler frame = new Handler();
private static final int FRAME_RATE = 40; // 1000ms/40ms = 25 frames per second
private PanZoomView w;
private TextView t;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
w = (PanZoomView) findViewById(R.id.zoomview);
t = (TextView) findViewById(R.id.tv_mPosX);
frame.post(frameUpdate);
}
private Runnable frameUpdate = new Runnable() {
@Override
public void run() {
t.setText("mScaleFactor =" + w.get_mScaleFactor());
frame.postDelayed(frameUpdate, FRAME_RATE);
}
};
}