[Solved] Android How to change layout_below to TextView programmatically


I see 2 ways.

First way, you need to create new layout with same name but in folder layout-land, copy all content here and remove layout_below rule.
In this case, you just declare another layout, which not contains layout_below rule

See this screenshot:

2 layout for different orientation

This means, that you defined different layouts for different orientation.
in layout/my_layout.xml:

<TextView
        android:id="@+id/aaa"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/xxx" />

in layout-land/my_layout.xml:

<TextView
            android:id="@+id/aaa"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

For more information, see this link:

Table 2. Configuration qualifier names, row with name “Screen orientation”

Second way, in your java code(onCreate() method for example):

if(Activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
    RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) yourView.getLayoutParams();
    lp.addRule(RelativeLayout.BELOW, 0);
    yourView.setLayoutParams(lp);
}

EDITED

2

solved Android How to change layout_below to TextView programmatically