以编程方式对齐RelativeLayout中的文本视图

时间:2010-08-08 09:30:30

标签: android textview relativelayout

我无法调用setContentView来显示XML布局 - 我只能获得一个可以通过编程方式修改的RelativeLayout。现在,我需要做的是添加一个简单的TextView,在RelativeLayout的底部对齐。使用XML可以很简单:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" 
    android:maxLines="5"
    android:scrollbars="vertical"
    android:text="some text"
    />
</RelativeLayout>

我一直在尝试使用代码执行此操作的各种方法,但我无法使其正常工作。我已经尝试过textView.setGravity(Gravity.BOTTOM)和relativeLayout.setVerticalGravity(RelativeLayout.ALIGN_PARENT_BOTTOM),但那些都没有用。我可以通过填充它来将其推下来,但我不希望它填满整个屏幕。

0 个答案:

没有答案