【问题标题】:Why android button does align from top edge, but not from bottom edge?为什么android按钮确实从顶部边缘对齐,而不是从底部边缘?
【发布时间】:2013-09-12 01:13:27
【问题描述】:

我有一个按钮,我可以将它与顶部的距离对齐。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/m1"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".OtherScreenActivity1" >

        <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="99dp"
            android:background="@drawable/btn" />

</RelativeLayout>

但我想通过与底部的距离而不是与顶部的距离来对齐它的位置,它不起作用,它一直粘在底部。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/m1"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".OtherScreenActivity1" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="99dp"
            android:background="@drawable/btn" />

</RelativeLayout>

【问题讨论】:

  • 这个android:layout_marginBottom="99dp"应该可以工作

标签: android button alignment


【解决方案1】:

不确定是什么问题,但这是我目前的问题,代码似乎工作正常

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
tools:context=".OtherScreenActivity1" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="99dp"
        />

试试这段代码,看看 xml 是不是你要找的。​​p>

【讨论】:

    猜你喜欢
    • 2014-10-10
    • 1970-01-01
    • 2020-03-04
    • 2018-06-06
    • 2016-11-03
    • 2020-08-10
    • 1970-01-01
    • 2014-01-28
    • 2011-08-28
    相关资源
    最近更新 更多