-1

这是我的第一个问题!我有一个活动(MainActivity)和一个可以缩放的视图(PanZoomView)。布局是

<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;
 ...

我在哪里/如何处理这个?

谢谢大家,里卡多

4

1 回答 1

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);
        }
};

}

于 2013-09-19T07:21:21.900 回答