2015-05-29 68 views
0

我有一個RelativeLayout @+id/main_layout
@+id/main_layout裏面,我有一個TextView @+id/txt1和一個RelativeLayout @+id/store
出於某種原因,我必須將android:layout_below="@+id/txt1"設置爲內部RelativeLayout @+id/store編程。怎麼做?以相對佈局編程設置RelativeLayout layout_below

+0

use setLayoutParams(RelativeLayout.LayoutParams);並使用[this]設置你的規則(http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html#addRule%28int,%20int%29) – shobhan

回答

3

你能嘗試添加這樣的:

RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 
relativeParams.addRule(RelativeLayout.BELOW, idOfTheViewBelow); 

當然,使用的參數(填寫父母等),你需要的!

編輯:當然,你不需要創建RelativeLayout,只是實例化你自己的,並應用你需要的規則!