Методы получения позиции вида возвращают 0

Этот вопрос задавался несколько раз, но все называют причину, по которой это происходит (т.е. расчет происходит до того, как макет уложен). Но мне нужно решение этой проблемы. Я пробовал getBottom();, getTop();, getLocationOnScreen(int[] location);. Но все они возвращают значение Zero (0). Я даже пытался передать их в onStart();, чтобы дать время для укладки макета, но безуспешно. Вот мой код:

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

Layout 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>

Еще раз извиняюсь за повторение вопроса. Заранее спасибо.

8
задан Kartik 16 January 2012 в 11:42
поделиться