2011-12-21 91 views
0

我真的很久没有回到Android了,事实证明,我几乎忘记了一切。我应该选择哪种布局?

我想构建这样的UI:

enter image description here

按钮项目1和项目2触发移动到另一个页面,而执行操作按钮不到位的动作。广告应该停靠在屏幕的底部。

我应该选择哪种布局来实现此UI? 我针对的是Android 2.2(如果有的话)。

+0

@ Dr.nik我试过表的布局,但它是不切实际的。 – AngryHacker 2011-12-21 06:32:51

+0

按照rahul请尝试与相对布局 – 2011-12-21 06:35:13

回答

4

我相信去相对布局有帮助。可能会有所帮助,虽然你可能想重新洗牌一下。

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

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="42dp" 
      android:text="@string/item1" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/button1" 
      android:layout_below="@+id/button1" 
      android:layout_marginTop="48dp" 
      android:text="@string/item2" /> 

     <Button 
      android:id="@+id/button4" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:text="@string/ad_goes_here" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/button2" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="62dp" 
      android:text="@string/perform_action" /> 

    </RelativeLayout> 
+0

+1为确切的捕获,但请详细说明你回答与例子,因为他自己提到他忘记了一切 – ingsaurabh 2011-12-21 06:35:28

+0

@ingsaurabh:是啊,编辑它.. :) – Ghost 2011-12-21 06:36:48

+0

@AngryHacker:我插入按钮在该广告的位置。您随时可以使用适合您广告的确切说明进行更改。 – Ghost 2011-12-21 06:39:16

2

您可以使用android:orientation="vertical"一个LinearLayout。然而,还有很多其他的布局能够实现你想要的用户界面。我宁愿坚持LinearLayout,因为我可以将它设置为垂直或水平。

+0

如何确保广告停靠在底部? – AngryHacker 2011-12-21 06:31:33

+1

如果您需要将物品放置在底部,例如Rahul所说的相对布局会有所帮助。你可以使用'android:layout_alignParentBottom'。看看这个问题 - http://stackoverflow.com/questions/2386866/how-to-align-views-at-the-bottom-of-the-screen – Hend 2011-12-21 06:38:03

2

您可以在此布局中继续使用相对布局,您需要使用列表视图(简单)并在列表视图的下方拖动按钮。并在底部的地方您advertice SDK区域将被留

For more detail....

3
I think using Linear Layout is best 


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

<Button 
android:id="@+id/btn1" 
android:text="Item1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" android:layout_gravity="center" 
/> 

<Button 
android:id="@+id/btn2" 
android:text="Item2" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" android:layout_gravity="center" 
/> 
<Button 
android:id="@+id/btn3" 
android:text="Perform Action" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" android:layout_gravity="center" 
/> 

<Button 
android:id="@+id/btn4" 
android:text="Ad Goes here" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" android:layout_gravity="center" 
/> 

</LinearLayout>