2016-10-19 62 views
0

我的下一個XML:的LinearLayout變化大小

<RelativeLayout> 
<ImageView 
android:id="@+id/imageView1" 
android:src="@drawable/image_back" /> 

<LinearLayout 
android:id="@+id/linearLayoutNames" 
android:layout_height = "fill_parent" 
android:layout_weight = "fill_parent" 
android:layout_alignTop = "@+id/image_back" 
android:layout_marginTop = "38dp" /> 

<LinearLayout 
android:id="@+id/linearLayoutPoints 
android:layout_height = "wrap_content" 
android:layout_weight = "wrap_content" 
android:layout_alignBottom = "@+id/image_back" 
android:layout_below = "@+id/linearLayoutNames" /> 
</RelativeLayout> 

我的編程代碼:

LinearLayout linearLayoutPoints = (LinearLayout) findViewRoot(R.id.linearLayoutPoints); 
RelativeLayout.LayoutParams layoutParams = (android.widget.RelativeLayout.LayoutParams) linearLayoutPoints.getLayoutParams(); 
layoutParams.width = 200; 
layoutParams.height = 300; 
linearLayoutPoints.setLayoutParams(layoutParams); 

我想調整linearLayoutPoints但是當Y嘗試,什麼都不會發生!只調整它,如果我調整imageView1的大小,但我不想要的。 不知道爲什麼。

幫助

+0

爲什麼使用RelativeLayout.LayoutParams代替LinearLayout.LayoutParams? – aiqency

+1

,因爲我的linearLayout的parnt是相對佈局 – user3240604

回答

0

你可以試着這樣做:

layoutParms.setMargin(0, 0, 0, (layoutParms.height -200)); 

這可以工作,因爲你佈局的形象和antoher佈局之間的緊張。

+0

對不起,我在這裏寫wriong!我的錯誤,我將編輯我的問題 – user3240604

+0

你怎麼知道佈局的大小沒有改變?佈局中沒有元素。 – Timo

+0

另一個解決方案可能是刪除代碼中的規則alignBottom。 – Timo