Есть TextView мне нужно программно менять гравити для этой вьюхи.
Пробовал сделать так :
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
Но не нашел в них гравити. Попробовал сделать так:
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER_HORIZONTAL;
textView.setLayoutParams(params);
но кинуло ошибку:
java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
Вопрос: как можно задать гравити в моем случае?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/tv_main_word"
android:layout_width="match_parent"
android:layout_height="61dp"
android:layout_marginTop="38dp"
android:layout_marginBottom="28dp"
android:layout_marginLeft="38dp"
android:layout_marginRight="38dp"
android:singleLine="false"
android:text="customer acquisition cost"
android:textColor="@color/colorFontBlue"
android:textSize="23sp"
/>