この質問は何度か尋ねられましたが、なぜこのようなことが起こるのか(つまり、レイアウトが行われる前に計算が行われる)しかし、私はこれを解決する必要があります。試しましたgetBottom();
、getTop();
、getLocationOnScreen(int[] location);
です。しかし、すべてが値Zero(0)を返します。私は、レイアウトのための時間を与えるためにonStart();
にこれらを与えようと試みましたが、運はありません。ビューの位置を取得するメソッドは返されます。0
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.textView1);
Log.d("getBottom :", Integer.toString(tv.getBottom()));
Log.d("gettop :", Integer.toString(tv.getTop()));
int[] location = new int[2];
tv.getLocationOnScreen(location);
Log.d("getlocationonscreen values :", Integer.toString(location[0])+" "+Integer.toString(location[1]));
}
@Override
protected void onStart() {
Log.d("getBottom in onStart :", Integer.toString(tv.getBottom()));
Log.d("gettop in onStart :", Integer.toString(tv.getTop()));
int[] location = new int[2];
tv.getLocationOnScreen(location);
Log.d("getlocationonscreen in onStart :", Integer.toString(location[0])+" "+Integer.toString(location[1]));
super.onStart();
}
レイアウトXML::
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="156dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
は再び、私は質問を繰り返す謝罪 は、ここに私のコードです。前もって感謝します。
あなたの正確な問題は何かもっと説明してください。上記のコードで何が間違っているのでしょうか。 –