-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 オブジェクトにゲッターを実装しました

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 に答える