Iam在xml文件中使用下面的代码,并通过使用textview编程添加子视图,但我需要去特定的位置(假设在每个文本视图IAM添加数字从1开始,然后我想要从总共10个文字浏览第5个位置textview)使用scrollview的视图。我知道滚动的方法,但我不知道如何计算xy cooardinates从这个layout.Please指导。如何从线性布局获取特定位置的xy坐标android?
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:scrollbars="vertical"
android:id="@+id/agenda_scroll"
>
<LinearLayout android:id="@+id/inner_layout"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
</ScrollView>
Suppost我的代码是这样的
ScrollView scview = (ScrollView)findViewById(R.id.Scl);
LinearLayout eventLayout = (LinearLayout) findViewById(R.id.inner_layout);
TextView txtView = new TextView(cx);
txtView.setText("1");
eventLayout.addView(txtview);
TextView txtView = new TextView(cx);
txtView.setText("2");
eventLayout.addView(txtview);
TextView txtView = new TextView(cx);
txtView.setText("3");
eventLayout.addView(txtview);
TextView txtView = new TextView(cx);
txtView.setText("4");
eventLayout.addView(txtview);
TextView txtView = new TextView(cx);
txtView.setText("5");
int y = txtview.getTop();
Log.d(TAG,"YAxis"+y);//returning 0
eventLayout.addView(txtview);
TextView txtView = new TextView(cx);
txtView.setText("6");
eventLayout.addView(txtview);
.........
scview .scrollTo(0,y);///here positions giving (0,0)
我试过所有上述方法,但它仍然给坐标0,0 – ADIT 2011-05-17 05:36:52
@ADIT:哪个上面的方法? getTop()和getLeft()将返回0,直到布局为止。看到这个问题:http://stackoverflow.com/questions/3947145/what-event-is-fired-after-all-views-are-fully-drawn – bigstones 2011-05-17 10:17:27