2011-05-07 31 views
0

我想做Dashboard pattern。我目前做到這一點每個家庭按鈕:實現Dashboard UI模式的最有效方法?

<FrameLayout 
    android:layout_weight="1" 
    android:focusable="true" 
    android:onClick="onHomeButtonClicked" 
    android:background="@drawable/button_background"> 
    <TextView 
     android:text="@string/button_text" 
     android:drawableTop="@drawable/button_icon" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:background="@android:color/transparent" /> 
</FrameLayout> 

的原因,我總結我的按鈕,裏面的FrameLayout是我想:

  • 最大化可點擊區域
  • 製作圖標和文本正確 居中。

我想在過去這樣做,但放棄了,因爲我無法找出居中文本和圖標的屏幕大小無關的方式:

<Button 
    android:layout_weight="1" 
    android:background="@drawable/button_background" 
    android:text="@string/button_text" 
    android:onClick="onHomeButtonClicked" 
    android:drawableTop="@drawable/button_icon" 
    android:drawablePadding="DONT_KNOW_WHAT_TO_PUT_IN_HERE" /> 

我的問題:是否有可能做所有這些:

  1. (僅使用1按次 按鈕)
  2. 最大化點擊未包裹內的其他 佈局按鈕一個
  3. 正確居中的圖標和文字 一個屏幕大小無關的方式

非常感謝。

+0

檢查完您提供的鏈接之後,是否有理由不使用GridView創建儀表板模式?或者,你是如何填充這些佈局來顯示的呢? – harism 2011-05-07 09:17:40

+0

是否可以在XML佈局中聲明'GridView'的內容,或者我必須在Java中填充它們? – Phil 2011-05-07 18:32:15

回答

0

下面是一些代碼,我用它來編程構建一個儀表盤:

@Override public View getView(int position, View convertView, 
     ViewGroup parent) { 
    TextView v = (TextView) convertView; 
    if (v == null) { 
     v = new TextView(DashboardActivity.this); 
     v.setGravity(Gravity.CENTER); 
    } 
    v.setCompoundDrawablesWithIntrinsicBounds(0, 
     mIcons[position].drawableId, 0, 0); 
    v.setText(mIcons[position].labelId); 

    return v; 
} 

你也可以使用安卓drawableTop在一個XML文件,如果你能事先建立的儀表板。

相關問題