2012-04-24 66 views
0

我有一個應用程序的主屏幕布局,我想有一個evernote風格。 到目前爲止,我的代碼是這樣的:Android:Evernote風格佈局

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:gravity="center_vertical|center_horizontal" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|left" 
     android:orientation="horizontal" > 

     <ImageButton 
      android:id="@+id/btn1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/button" /> 

     <ImageButton 
      android:id="@+id/btn2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/button" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|center" 
     android:orientation="horizontal" > 

     <ImageButton 
      android:id="@+id/btn3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/button" /> 

     <ImageButton 
      android:id="@+id/btn4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/button" /> 
    </LinearLayout> 

</LinearLayout> 

這是它的樣子:

enter image description here

這是我想怎麼看起來像:

enter image description here

我怎麼能做到這一點?像這樣分組按鈕?

非常感謝!

+1

什麼,你可能尋找的是一個儀表盤模式。看看這個問題:http://stackoverflow.com/questions/2873568/android-dashboard-pattern - 第二個答案 – 2012-04-24 08:11:06

+0

http://stackoverflow.com/questions/8212035/android-gridlayout-and-space-backport – Siyamed 2012-04-24 08:29:09

回答

1

你可以把它適應這個,這是從谷歌I/O的應用程序。

<?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" 
android:background="#ffffff"> 
<LinearLayout android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:padding="6dip"> 
    <LinearLayout android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 
     <Button android:id="@+id/button" 
      android:text="@string/button" 
      android:drawableTop="@drawable/button" /> 
     <Button android:id="@+id/button" 
      android:text="@string/button" 
      android:drawableTop="@drawable/button" /> 
    </LinearLayout> 

    <LinearLayout android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 
     <Button android:id="@+id/button" 
      android:text="@string/button" 
      android:drawableTop="@drawable/button" /> 
     <Button android:id="@+id/button" 
      android:text="@string/button" 
      android:drawableTop="@drawable/button" /> 

    </LinearLayout> 

    <LinearLayout android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 
     <Button android:id="@+id/button" 
      android:text="@string/button" 
      android:drawableTop="@drawable/button" /> 
     <Button android:id="@+id/button" 
      android:text="@string/button" 
      android:drawableTop="@drawable/button" /> 
    </LinearLayout> 
</LinearLayout> 

+0

按鈕不要放大,這意味着它們不會擴大。因此我建議使用ImageView和TextView。 – 2012-04-24 12:29:22

+0

另一個問題是,文本視圖也不會按比例放大,但它不像圖像那麼大。 – 2012-04-24 12:30:02

+0

@kilaka這只是一個定位的例子。在我的情況下,我使用按鈕,他可以把他想要的任何東西。在我的應用程序中它工作得很好,我有類似於'Evernote'的東西。 – 2012-04-24 13:31:51

1

您只需要將ImageButtons的寬度設置爲0dp並給它們一個1的layout_weight。 此外,將layout_gravity設置爲center_horizo​​ntal。

這將使他們中心很好。

最良好的祝願, 添