【问题标题】:Aligning Android Button To Bottom in RelativeLayout?在RelativeLayout中将Android按钮与底部对齐?
【发布时间】:2011-06-08 03:32:09
【问题描述】:

我正在尝试使用 RelativeLayout 将按钮与屏幕的右下角和左下角对齐。我想这样做是为了在不同的屏幕尺寸上保持相同的相对布局。目前,我屏幕上的按钮会根据屏幕的分辨率上下移动。与 480x800 相比,320x480 将按钮放在屏幕上更高的位置。我正在尝试让两种尺寸的屏幕看起来相同。

【问题讨论】:

标签: android button alignment


【解决方案1】:

我知道这是一个旧线程,但它显示在搜索结果的顶部,所以我认为确认它不会有坏处

android:layout_alignParentBottom="true"  

在 RelativeLayout 中为我工作。

【讨论】:

    【解决方案2】:

    例子:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:panel="http://schemas.android.com/apk/res/it.kronplatz"
        android:id="@+id/MainLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <RelativeLayout
            android:id="@+id/ButtonLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_centerHorizontal="true"
            android:baselineAligned="false" >
    
            <ImageButton
                android:id="@+id/locateMeButton"
                android:layout_width="70px"
                android:layout_height="70px"
                android:layout_marginLeft="5px"
                android:src="@drawable/me" >
            </ImageButton>
    
            <ImageButton
                android:id="@+id/MapCenterButton"
                android:layout_width="70px"
                android:layout_height="70px"
                android:layout_alignParentRight="true"
                android:layout_gravity="right"
                android:layout_marginRight="5px"
                android:src="@drawable/fadenkreuz_klein" />
    
            <Button
                android:id="@+id/MapNextButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:drawableRight="@drawable/androidmarker" >
            </Button>
        </RelativeLayout>
    
    </RelativeLayout>
    

    【讨论】:

      【解决方案3】:

      你在使用 android:layout_alignParent* 吗?无论屏幕大小如何,这都应该证明它是合理的。

      其中 * 是底部或顶部或左侧或右侧

      【讨论】:

        【解决方案4】:

        除了 AedonEtLIRA 所说的,你应该确保你的 RelativeLayout 总是填满整个显示区域。 IE。您没有在视图层次结构中的任何位置定义任何大小,而是使用 match_parent。如果您随后使用 AedonEtLIRA 给出的布局定义,您应该得到您想要的。

        【讨论】:

          猜你喜欢
          • 2016-07-20
          • 2017-11-23
          • 1970-01-01
          • 1970-01-01
          • 2018-07-02
          • 1970-01-01
          • 1970-01-01
          • 2019-11-26
          相关资源
          最近更新 更多