2012-06-26 64 views
0

我想添加水平LinearLayout編程的第一個孩子寬度,確保老二的LinearLayout - 使基於第二

通吃的寬度需要與第一個孩子將剩下的全部空間。

我沒有要添加的代碼,因爲我嘗試了很多選項,而且還沒有任何工作。

有什麼想法嗎?

+0

給予第二個孩子的揮舞1給第一個孩子分配什麼分量 –

+0

?以及放在LayoutParams上的內容? – piojo

回答

0

文本設置爲android:layout_weight="0"第二個孩子。併爲第一個子集android:layout_weight="1"

+0

以及放在LayoutParams上的內容? – piojo

+0

TextView tv = new TextView(v.getContext()); tv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,1f)); __最後一個參數是重量.__ – Waqas

-1

嘗試這種變化的BUTTON3

<?xml version="1.0" encoding="UTF-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:weightSum="1.0" > 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Back" /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Read sad s as d" /> 

</LinearLayout> 
+0

你有沒有注意到這個詞**編程**? – Venky

+0

但可能在此之後,他可能需要在java代碼中更改..as每按鈕文本其他按鈕寬度得到減少....... –

+0

我需要編程,我想確保第二個孩子是可見的而不是第一個 – piojo

相關問題