코드상에서 실행해서 종종 레이아웃을 바꿔야 할 경우가 있다.

이럴 경우에는 java 파일 상에서 해결을 해 줘야 한다.

LinearLayout linear = (LinearLayout)findViewId(R.id.레이아웃아이디);
linear.setOrientation(LinearLayout.VERTICAL);

이런 식으로 바꿔주면 된다.

물론 레이아웃 뿐 아니라 다른 컴포넌트 역시 이런 식으로 바꿔주면 된다.
[Android] RelativeLayout Android 2011. 12. 12. 17:35
관계형 레이아웃이다. 모두 접두어에 layout_ 이 붙어 있고 다음이 그 관련된 설명이다

 속성  설명
 layout_above  ~의 위에
 layout_below  ~의 아래에
 layout_toLeftOf  ~의 왼쪽에
 layout_toRightOf  ~의 오른쪽에
 layout_alignLeft  ~의 왼쪽 변을 맞춘다
 layout_alignTop  ~의 위쪽 변을 맞춘다
 layout_alignRight   ~의 오른쪽 변을 맞춘다
 layout_alignBottom  ~의 아래쪽 변을 맞춘다
 layout_alignParentLeft  true 면 부모와 왼쪽 변 맞춘다
 layout_alignParentTop   true 면 부모와 위쪽 변 맞춘다 
 layout_alignParentRight  true 면 부모와 오른쪽 변 맞춘다
 layout_alignParentBottom  true 면 부모와 아래쪽 변 맞춘다
 layout_alignBaseline  ~와 베이스라인 맞춘다
 layout_alignWithParantIfMissing  속성에 앵커가 발생하지 않을 경우 부모를 앵커로 인지한다
 layout_aligncenterHorizontal  true 면 부모의 수평 중앙에
 layout_aligncenterVertical  true 면 부모의 수직 중앙에 
 layout_aligncenterInParent  true 면 부모의 수평 중앙에 

샘플은 다음과 같이 해서 확인해보면 알 수 있을 것이다.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     >    
 <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:id="@+id/btn1"
     android:text="first"
     android:layout_marginRight="15px"
 />
 <TextView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:id="@+id/btn2"
  android:text="second"
  android:layout_toRightOf="@id/btn1"
 />
 <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:id="@+id/btn3"
     android:text="third"
     android:layout_below="@id/btn2"
 />
</RelativeLayout>