/ / Jak dodać Wyświetl programowo RelativeLayout do RelativeLayout - android, układ android, układ

Jak dodać programowo program RelativeLayout do programu RelativeLayout - Android, układ androida, układ

Mój xml lubi to:

<ScrollView>
<RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_comment"
android:layout_below="@+id/divider_daily"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
</ScrollView>
<com.myfitness.MyFitness.utils.customfont.CustomTextView
android:id="@+id/btn_start_workout"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/background_btn_start_workout"
android:gravity="center"
android:text="@string/btn_start_workout"
android:textColor="@color/white"
android:textSize="20sp" />

Kiedy klikam przycisk, chcę przenieść TextView poza ScrollView do RelativeLayout poniżej RecyclerView.

Myślę, że powinienem użyć LayoutParams, ale nie wiem jak, bardzo będę wdzięczny, jeśli ktoś pokaże mi drogę, tks.

Odpowiedzi:

0 dla odpowiedzi № 1
RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams( RelativeLayout.WRAP_CONTENT,RelativeLayout.WRAP_CONTENT);
params.addRule(RelativeLayout.BELOW,R.id.rv_comment);
params.setMargin(0,16,0,0);
tv.setLayoutParams(params);

0 dla odpowiedzi nr 2

Dodaj Relativelayout jako rootview i linearlayout jako element nadrzędny zawartości. Użyj jego orientacji, aby ustawić widok tekstu poniżej viewera.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.RecyclerView
android:id="@+id/rv_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"></android.support.v7.widget.RecyclerView>
</ScrollView>

<com.myfitness.MyFitness.utils.customfont.CustomTextView
android:id="@+id/btn_start_workout"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:background="@drawable/background_btn_start_workout"
android:gravity="center"
android:padding="10dp"
android:text="@string/btn_start_workout"
android:textColor="@color/white"
android:textSize="20sp" />
</LinearLayout>
</RelativeLayout>