私はビューの座標を取得することに問題があります。 LinearLayoutには3つのカスタムビューが配置されています。私がそれらのいずれかに触れると、私は座標が間違っています。たとえば、2番目のビューは中央に配置されますが、getLocationOnScreen()はx = 0を返します。これは不可能です。 この座標は、event.getX()とevent.getY()を介して取得できる値とは常に異なります。Android getLocationOnScreen問題:座標が間違っています
教えてください。問題は何ですか? (Log.wスルー)
結果
まず図:onTouch_coords:0、50
第2のビュー:onTouch_coords:0、98
第ビュー:onTouch_coords:0、146
これはgui xmlファイルです:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.remaller.android.DragAndDropBasicsInheriting.DragableView
android:id="@+id/DragableView1"
android:layout_height="wrap_content"
android:src = "@drawable/icon" android:layout_width="wrap_content"/>
<com.remaller.android.DragAndDropBasicsInheriting.DragableView
android:id="@+id/DragableView2"
android:layout_height="wrap_content"
android:src = "@drawable/icon" android:layout_width="match_parent"/>
<com.remaller.android.DragAndDropBasicsInheriting.DragableView
android:id="@+id/DragableView3"
android:src = "@drawable/icon" android:layout_width="wrap_content" android:layout_height="match_parent"/>
</LinearLayout>
これはソースコードですまたは私のDragableView:それは常にDragableView
a.k.a、this
ビューの位置を返します
public class DragAndDropBasicsInheritingActivity extends Activity
{
public static final int CREATE = 0x00000001;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.draganddropbasicsinheritingactivity_gui);
}
}