Android: textView-set y-coordinate dynamically
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:
Have you thought about using a RelativeLayout
and use align_parent_bottom
?
http://developer.android.com/reference/android/widget/RelativeLayout.html
What if you change the height of the TextView
only? You said...
the height increases from top to bottom
So... in that case you can align the TextView
at the bottom. For instance, if you are using RelativeLayout
as the container of the TextView
, you can use android:layout_alignParentBottom="true"
.
精彩评论