Android:textView动态设置y坐标
我尝试使用 textview.setTranslationY(float) 更改 textview 的 y 坐标,但它似乎不起作用。 textview.setTop() 似乎执行相同的功能,但文档说此方法应该由布局系统调用,通常不应以其他方式调用,因为布局可能随时更改该属性。 我使用 textview.getTranslationY() 来获取 y 坐标。
如何设置textview的y坐标?如果我上面做的事情是错误的,请建议其他方法。也许还有另一种设置 y 坐标的方法,我还没有找到!
我的情况:我有一个文本视图,其高度应该根据收到的某些值而变化。如果我使用textview.setHeight(int),高度从上到下增加。我希望它从下到上增加。因此,每次设置文本视图的高度时,我都会更改它的 y 坐标。
干杯,
Madhu
我的布局的屏幕截图:
I tried using textview.setTranslationY(float) to change the y-coordinate of the textview but it does not seem to work. textview.setTop() seems to do the same function but the documentation says this method is meant to be called by the layout system and should not generally be called otherwise, because the property may be changed at any time by the layout.
I use textview.getTranslationY() to get the y-coordinate.
How can I set the y-coordinate of textview? If what I am doing above is wrong, kindly suggest an alternative way. Maybe there is another method to set y-coordinate which I have not found yet!
My situation: I have a textview whose height should change based on some value received. If I use textview.setHeight(int), the height increases from top to bottom. I want it to increase from bottom to top. So I change the y-coordinate of the textview every time I set it's height.
Cheers,
Madhu
Screen shot of my layout:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否考虑过使用
RelativeLayout
并使用align_parent_bottom
?http://developer.android.com/reference/android/widget/RelativeLayout.html
Have you thought about using a
RelativeLayout
and usealign_parent_bottom
?http://developer.android.com/reference/android/widget/RelativeLayout.html
如果仅更改
TextView
的高度会怎样?你说...所以...在这种情况下,您可以在底部对齐
TextView
。例如,如果您使用RelativeLayout
作为TextView
的容器,则可以使用android:layout_alignParentBottom="true"
。What if you change the height of the
TextView
only? You said...So... in that case you can align the
TextView
at the bottom. For instance, if you are usingRelativeLayout
as the container of theTextView
, you can useandroid:layout_alignParentBottom="true"
.