2014-05-04 39 views
-2

這是修改後的版本!我是新來的編程Android應用程序,我認爲這是非常困難的,不是Java而是UI。我正在嘗試獲取類別列表。它們可以是listView或其他內容中帶有textview的複選框。想法是,用戶可以按下框/標籤/複選框/按鈕,多選。我結束了複選框,因爲它感覺最簡單的方法,任何建議如何爲最終用戶獲得最簡單的解決方案?用戶可以添加他自己的類別,因此最後一行就像按鈕,用戶可以在其中添加新類別。ListView和佈局。爲什麼ListView與一切重疊?

問題

我怎樣才能得到一個佈局,其中的類別複選框不重疊設置欄,按鈕等 部分解決:我改變了對的FrameLayout和的LinearLayout我改變了我的開機畫面從ImageView的到android:佈局的背景。現在我可以看到一切,但順序不對。如果我移動topframe頂部(這裏應該是),我得到了這樣的錯誤消息:

錯誤: java.lang.ClassCastException:android.widget.LinearLayout不能轉換爲android.widget.Button

ACTIVITY.xml

<LinearLayout 
    android:id="@+id/buttonContainer" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="bottom" 
    android:orientation="vertical" > 

    <Button 
     android:id="@+id/category" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top" 
     android:layout_marginBottom="5dp" 
     android:layout_marginLeft="30dp" 
     android:layout_marginRight="30dp" 
     android:background="@drawable/white_button" 
     android:minHeight="40dp" 
     android:text="@string/category" 
     android:textColor="#ffffff" 
     android:textStyle="bold" /> 

    <Button 
     android:id="@+id/tak" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="5dp" 
     android:layout_marginLeft="30dp" 
     android:layout_marginRight="30dp" 
     android:background="@drawable/white_button" 
     android:minHeight="40dp" 
     android:text="@string/take" 
     android:textColor="#ffffff" 
     android:textStyle="bold" /> 

    <Button 
     android:id="@+id/list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top" 
     android:layout_marginBottom="5dp" 
     android:layout_marginLeft="30dp" 
     android:layout_marginRight="30dp" 
     android:background="@drawable/white_button" 
     android:minHeight="40dp" 
     android:text="@string/list" 
     android:textColor="#ffffff" 
     android:textStyle="bold" /> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/topframe" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#99a8b3b9" > 

    <Button 
     android:id="@+id/settings_button" 
     android:layout_width="43dp" 
     android:layout_height="37dp" 
     android:background="@drawable/ic_sysbar_quicksettings" /> 

    <TextView 
     android:id="@+id/top_category" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="30dp" 
     android:text="@string/no_category_text" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#FFFFFF" /> 
</LinearLayout> 

enter image description here

+0

什麼是你的父母在的ViewGroup佈局? –

+0

我剛剛來到這裏,我認爲這是問題所在。 Sami

回答

1

不要使用FrameLayout裏建立這樣的UI。 FrameLayout將所有孩子放在左上角,這就是爲什麼你的視圖重疊。我所看到的具有垂直方向的LinearLayout應該可以完成這項工作。

使用一個這樣的例子:

<LinearLayout 
    ... 
    android:orientation="vertical"> 

    ... 

    <LinearLayout 
     android:id="@+id/topframe" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="#99a8b3b9" > 

     <Button 
      android:id="@+id/settings_button" 
      android:layout_width="43dp" 
      android:layout_height="37dp" 
      android:background="@drawable/ic_sysbar_quicksettings" /> 

     <TextView 
      android:id="@+id/top_category" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="30dp" 
      android:text="@string/no_category_text" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="#FFFFFF" /> 
    </LinearLayout> 

    <ListView 
     android:id="@+id/listView1" 
     android:layout_width="fill_parent" 
     android:layout_height="377dp" > 
    </ListView> 

    ... 

</LinearLayout> 
+0

我也會試試這個。我認爲這些按鈕可能會與背景圖像重疊,我只是猜測... – Sami

+0

我試過了,現在我只能看到一個啓動畫面,沒有複選框,沒有按鈕,只有閃屏圖像。 Sami

+0

編輯:我摘下了imageview,並用linearLayout中的android:background =「@ drawable/splash」>來代替。現在,這是工作,但按鈕是最上面的,然後topframe,然後複選框。這個很有趣 :) – Sami