0

レイアウトに次の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:orientation="vertical"
    android:paddingLeft="10dip"
    android:paddingRight="10dip"
    android:paddingBottom="20dip"
    tools:context=".ZoneSelectionActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:paddingTop="10dip"
        android:textSize="35sp"
        android:paddingBottom="10dip"
        android:text="@string/affected_zone" />

    <FrameLayout
        android:id="@+id/imageHolder"
        android:layout_gravity="center"
        android:background="#0B3861"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ImageView
                android:id="@+id/subsegment"
                android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
                android:contentDescription="subsegment"
                android:src="@drawable/sub_segment01" />

    </FrameLayout>  

</LinearLayout>

そして、これが私のスクリーンショットです。画面上のマークされたポイント(画像の左上隅のx、y)の座標が必要です。どのようにそれを決定することができますか?

スクリーンショット

4

4 に答える 4

1
int coords[] = {0,0};
yourImageView.getLocationOnScreen(coords);
int x = coords[0];
int y = coords[1];
于 2012-10-15T11:04:22.243 に答える
1

を使用しますView.getLocationOnScreen()。レイアウト フェーズ後にのみ呼び出すことができます。

于 2012-10-15T11:09:37.667 に答える
0

試す

View v;
int x = v.getLeft();
int y = v.getTop();
于 2012-10-15T12:19:20.600 に答える
0

ImageView が画面上の画像の位置を取得する方法を提供しているかどうかはわかりません。

ImageView 自体の場所のみを照会できます。

ImageView.getImageMatrix() を使用してみてください。ただし、画像が中央に配置されている (スケーリングされていない) 場合にデータが取り込まれるかどうかはわかりません

于 2012-10-15T11:10:42.460 に答える