2011-05-19 69 views
-2

我想在屏幕頂部並排放置5個圖像。 當我點擊一個圖像,我想顯示另一個圖像水平列表 任何人可以建議我嗎?我們如何將菜單放在屏幕上?

+5

你還沒有接受一個單一的答案,你問另一個,這很簡單,「請解決我的問題,我甚至沒有嘗試」。你真的認爲人們會幫助你嗎? – 2011-05-19 13:59:11

+0

瞭解Android如何讓您排列圖像,然後以這種方式排列圖像。 – 2011-05-19 14:51:01

回答

0

例如,可以創建在佈局XML文件2個嵌套水平LinearLayouts,與第二個是空的,但具有ID,像這樣:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<LinearLayout android:id="@+id/linearLayout1" 
    android:layout_height="wrap_content" android:layout_width="fill_parent" 
    android:orientation="horizontal"> 
    <ImageButton android:layout_height="wrap_content" android:id="@+id/imageButton1" android:src="@drawable/icon" android:layout_width="wrap_content" android:padding="0px"></ImageButton> 
    <ImageButton android:layout_height="wrap_content" android:id="@+id/imageButton2" android:src="@drawable/icon" android:layout_width="wrap_content" android:padding="0px"></ImageButton> 
    <ImageButton android:layout_height="wrap_content" android:id="@+id/imageButton3" android:src="@drawable/icon" android:layout_width="wrap_content" android:padding="0px"></ImageButton> 
    <ImageButton android:layout_height="wrap_content" android:id="@+id/imageButton4" android:src="@drawable/icon" android:layout_width="wrap_content" android:padding="0px"></ImageButton> 
</LinearLayout> 
<LinearLayout android:id="@+id/linearLayout2" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal"></LinearLayout> 

如果是Java代碼可以添加第二圖像的行動態地,經由第一行按鈕onClickListeners,像這樣(例如只增加1倍的圖像到第二行):

firstButtonInFirstLine = (ImageButton) findViewById(R.id.imageButton1); 
    firstButtonInFirstLine.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      LinearLayout secondLinearLayout = (LinearLayout) findViewById(R.id.linearLayout2); 

      ImageButton btn = new ImageButton(MainAct.this); 
      btn.setImageResource(R.drawable.misc); 
      secondLinearLayout.addView(btn); 
     } 
    }); 

可以實現同樣的事情可點擊的Imag eView元素。

相關問題