2012-04-04 56 views
0

说我想列出按钮,以便最后一个锚定到屏幕的底部,我将如何去解决这个问题。根据我的理解,LinearLayout会给我按钮的“列表”,但它会固定在顶部。另一方面,RelativeLayout将允许我锚定到底部,但每个元素都必须具有对下一个元素的引用,并且XML文件将以相反的顺序(以便引用有效)。触发器元素到屏幕底部而不使用RelativeLayout

我该如何解决这个问题?

编辑:道歉,这将是大约是我要寻找 -

screenshot

+0

为了确保我们得到这个权利,我建议你弹出您喜爱的图形编辑器(油漆,GIMP ...等),然后画出你想要的东西,并把它添加为一个图像到您的文章。相对的布局听起来是正确的,但我相信社区中的其他人和我一样会确保我们给出正确的建议。 – 2012-04-04 17:04:28

回答

1

我很难完全理解你的问题。 但我想你想要的是一个水平的按钮列表,它锚定在屏幕底部?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <!-- put your other views in here --> 

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

     <Button 
      android:id="@+id/button_cancel" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:padding="5dp" 
      android:text="cancel" /> 

     <Button 
      android:id="@+id/button_ok" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:padding="5dp" 
      android:text="ok" /> 
    </LinearLayout> 
</LinearLayout> 
+0

android:layout_gravity =“bottom” - 当然! – stephenfin 2012-04-04 17:14:53

2

你可以尝试添加一个额外的LinearLayout重量为1〜占用所有剩余空间,并按钮的列表推到活动的底部:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    android:id="@+id/widget32" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
<LinearLayout 
android:layout_width="fill_parent" 
    android:layout_height="0dp" 
android:layout_weight="1"> 
</LinearLayout> 
<Button 
    android:id="@+id/widget33" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" /> 
</LinearLayout> 

示例XML为单个按钮被通过的LinearLayout到活动的底部被推;根布局也是线性的。

+0

谢谢!很适合我在屏幕底部定位按钮,而不需要'RelativeLayout' – Konayuki 2017-02-02 08:26:52

相关问题