2011-07-09 33 views
0

看看草图的布局。用什么容器来获得这样的布局?

我需要有位于屏幕的中间5个按钮和安排这样的。我应该使用什么样的容器元素 - TableLayoutRelativeLayout或某些第三种布局?

+0

如果是这样的功课,记住使用作业标志。 –

+0

那么,不,只是更复杂的布局的一部分:)) – sandalone

回答

2

在这种情况下,我会用这样的

<LinearLayout android:orientation="vertical" ....> 
    <RelativeLayout ... > 
     // place the buttons in the desired padding 
    </RelativeLayout> 
    <RelativeLayout ... > 
     <Button ... android:layout_centerHorizontal="true" ... /> 
    </RelativeLayout> 
    <RelativeLayout ... > 
     // place the buttons in the desired padding 
    </RelativeLayout> 
</LinearLayout> 
+0

这看起来不错。明天将尝试第一件事。 – sandalone

0

我建议使用相对possition elemnts(或绝对取决于它是否在一个容器或没有)

2

您可以使用相对布局,

第1步:创建您的第一个按钮,然后创建第二个按钮使所述第二按钮leftof到第一按钮

第二步:创建下面的第一个按钮的第三个按钮

步骤3:创建下面的第三个按钮,第四和第五键

0

由于看起来你总是希望它们像你显示的行一样,但不希望它们在列中,所以我不会去看TableLayout。 RelativeLayout很好。

或者,像这样组合布局如何?我刚掀起这件事(见android:gravity属性,看看它是如何工作):

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" android:gravity="center_vertical"> 
    <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"> 
     <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
     <Button android:text="Button" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
    </LinearLayout> 
    <LinearLayout android:id="@+id/linearLayout2" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"> 
     <Button android:text="Button" android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
    </LinearLayout> 
    <LinearLayout android:id="@+id/linearLayout3" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"> 
     <Button android:text="Button" android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
     <Button android:text="Button" android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
    </LinearLayout> 

</LinearLayout> 
+0

按钮之间的空间呢?这样他们会触及对方,对吗?! – sandalone

+1

你想要多少空间?你没有在你的问题中说过。 :P如果您在Eclipse中按原样查看该布局,则应该看到它们在外观上不会触摸,但它们可以触及的矩形的确如此。如果您希望它们之间有更多空间,请根据您的需要在每个按钮或每个子布局上指定边距。请记住使用dp单位而不是px。 :) – Ribose

相关问题