Programmatically align text view in RelativeLayout

I cannot call setContentView to display XML layouts - I can only get a RelativeLayout, which I can programmatically change. Now I need to add a simple TextView aligned at the bottom of this RelativeLayout. With XML, it will be as simple as:

<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>

I tried various ways to do this with code, but I can't get it to work correctly. I tried textView.setGravity (Gravity.BOTTOM) and relativeLayout.setVerticalGravity (RelativeLayout.ALIGN_PARENT_BOTTOM), but that did not work. I can drop it by adding it, but I do not want it to fill the entire screen.

+3
source share

Source: https://habr.com/ru/post/1758590/


All Articles