2013-07-27 84 views
2

我喜歡設計一個如下圖所示的佈局。設計這種佈局的最佳方式是什麼,所以圖標將會在框中居中,如果我們在大屏幕上加載它,整個屏幕應該適合這8個盒子?如何設計適合整個屏幕的網格佈局?

enter image description here

+0

? – Luksprog

+0

我試圖在ImageView中使用網格佈局和相對佈局。但沒有得到確切的結果。在大屏幕上也不適合整個屏幕。 – jquery404

回答

2

這裏你會如何做佈局的例子:你是如何試圖使這個簡單的佈局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout_main" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <View 
     android:id="@+id/middle_separator" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_centerHorizontal="true" /> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_alignRight="@id/middle_separator" 
     android:orientation="vertical" > 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:background="#000000" > 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:src="@drawable/ic_launcher" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Stuff" 
       android:textColor="#ffffff" /> 
     </FrameLayout> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:background="#220000" > 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:src="@drawable/ic_launcher" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Stuff" 
       android:textColor="#ffffff" /> 
     </FrameLayout> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:background="#440000" > 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:src="@drawable/ic_launcher" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Stuff" 
       android:textColor="#ffffff" /> 
     </FrameLayout> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:background="#660000" > 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:src="@drawable/ic_launcher" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Stuff" 
       android:textColor="#ffffff" /> 
     </FrameLayout> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@id/middle_separator" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:orientation="vertical" > 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:background="#880000" > 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:src="@drawable/ic_launcher" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Stuff" 
       android:textColor="#ffffff" /> 
     </FrameLayout> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:background="#aa0000" > 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:src="@drawable/ic_launcher" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Stuff" 
       android:textColor="#ffffff" /> 
     </FrameLayout> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:background="#cc0000" > 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:src="@drawable/ic_launcher" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Stuff" 
       android:textColor="#ffffff" /> 
     </FrameLayout> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:background="#ee0000" > 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:src="@drawable/ic_launcher" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Stuff" 
       android:textColor="#ffffff" /> 
     </FrameLayout> 
    </LinearLayout> 

</RelativeLayout> 
+0

好主意Luk .. + 1 – Anirudha

+0

謝謝一堆。奇蹟般有效。但除外。如何做到這一點?它說「無法解析資源」 – jquery404

+0

@ jquery404這是一個''標籤(帶大寫字母),而不是''。 – Luksprog