2015-12-07 14 views
0

設置layout_toEndOf和layout_toRightOf編程我要編程設置這些屬性: -如何在TextView的

android:layout_toEndOf="@+id/imageView1" 
android:layout_toRightOf="@+id/imageView1" 
+2

使用'addRule()'方法對視圖的[RelativeLayout.LayoutParams](http://developer.android.com/reference/android/插件/ RelativeLayout.LayoutParams.html)。 –

回答

7

觀的父或母,有是順理成章的RelativeLayout的。然後,你可以做

final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
params.addRule(RelativeLayout.RIGHT_OF, R.id.imageView1); 
params.addRule(RelativeLayout.END_OF, R.id.imageView1); 

,並呼籲

view.setLayoutParams(params);