2013-07-27 149 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