繁体   English   中英

如何在oncreate(android)中以编程方式移动到屏幕上的其他x,y位置

[英]How to move to a different x,y location on a screen programatically in oncreate(android)

开始活动后,我希望屏幕移至x = 5000,y = 0。 我使用以下方法尝试实现这一目标:

//以帮助将焦点移至主视图。

TextView textView = new TextView(this);
textView.setFocusable(true);
textView.setVisibility(View.INVISIBLE);
params.setMargins(5000,0,10,10);
rl.addView(textView,params);
textView.requestFocus();

但是,它不起作用,焦点没有移到该位置。 任何帮助表示赞赏!

通过API 11,您可以执行以下操作

textView.setTranslationX(5000);

或者,如果您想更改Y,请使用:

textView.setTranslationY(your value expecting an int));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM