2012-06-26 106 views
1

我的父級佈局是一種線性佈局,而我正在嘗試添加兩種線性佈局。因爲某些原因。唯一會顯示的佈局是帶有兩個按鈕的線性佈局,另一個從不會出現....任何建議?兩種線性佈局但只有一種顯示

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent" 
android:orientation="vertical"> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="140dp" 
    android:layout_weight="2" 
    android:orientation="vertical"> 
    <TextView 
      android:id="@+id/dynamic_actionsText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Text"/> 
    <Spinner 
      android:id="@+id/dynamic_actionsSpinner" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 
</LinearLayout> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="240dp" 
    android:layout_weight="2" 
    android:orientation="vertical"> 
    <Button android:id="@+id/dynamic_btnSubmit" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1.0" 
      android:visibility="gone"/> 
    <Button android:id="@+id/dynamic_btnSave" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1.0" 
      android:visibility="gone"/> 
</LinearLayout> 
</LinearLayout> 
+0

提供完整的XML ........ –

+0

完整的代碼發佈。 – user1424489

+0

看到答案....... –

回答

0

首先拆下可視性消失(如通過Dheeresh提及)

現在,按鈕的機器人:layout_height = 「WRAP_CONTENT」 就是問題所在。

由於按鈕在他們沒有文字內容的高度基本上是= 0(WRAP_CONTENT的行爲)

添加屬性爲機器人:文本=‘你好’,在這兩個按鈕。你應該能夠看到他們。

如果你打算做動態整個操作然後做如下,

Button btnSubmit=(Button) findViewById(R.id.dynamic_btnSubmit); 
btnSubmit.setText("Submit"); 
Button btnSave=(Button) findViewById(R.id.dynamic_btnSave); 
btnSave.setText("Save"); 
btnSubmit.setVisibility(VIEW.VISIBLE); 
btnSave.setVisibility(VIEW.VISIBLE); 
+0

但是他提到,實際上可見的那個是帶有按鈕的那個,所以假設「wrap_content」屬性是錯誤的,那麼他必須將背景放在代表屏幕大部分屏幕的按鈕的代碼上。但即使是這種情況,重量屬性會阻止這種情況發生。不是嗎? – Raykud

0
any suggestions? 

建議:

1 - 設置方向垂直於父母雙方的LinearLayout的.....

2-刪除安卓知名度= 「水漲船高」,從dynamic_btnSubmit和dynamic_btnSave

<?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="vertical" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="140dp" 
     android:layout_weight="2" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/dynamic_actionsText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Text" /> 

     <Spinner 
      android:id="@+id/dynamic_actionsSpinner" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="240dp" 
     android:layout_weight="2" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/dynamic_btnSubmit" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1.0" /> 

     <Button 
      android:id="@+id/dynamic_btnSave" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1.0" /> 
    </LinearLayout> 

</LinearLayout> 

enter image description here

+0

我嘗試了這些更改,但仍然只剩下一個線性佈局。 – user1424489

+0

看到編輯後的代碼在我的末端正常工作 –

+1

謝謝。代碼現在可用。 – user1424489