【问题标题】:Android relativeLayout: How to make button take bottom port of screen?Android relativeLayout:如何使按钮占据屏幕的底部?
【发布时间】:2014-11-01 02:06:43
【问题描述】:

我想知道我是否可以创建一个按钮来占据屏幕底部,如下所示:

我尝试过调整对齐和边距,但无济于事:

我的另一个问题是为什么我的电影海报没有正确对齐顶部文字的左侧?可以看出,它有点偏右。我曾试图将其拖入到位。

这是我的 XML:

<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="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.abushawish.randommovie.MainActivity$PlaceholderFragment" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button1"
    android:layout_alignParentTop="true"
    android:layout_marginTop="14dp"
    android:text="Black Hawk Down"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/textView3"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:src="@drawable/bhd" />

<Button
    android:id="@+id/button1"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:text="New Movie Suggestion"
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_marginLeft="-50dp"
    android:layout_marginRight="-50dip"
    android:layout_marginBottom= "-20dp" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_centerVertical="true"
    android:text="Description"
    android:layout_marginLeft="1dp" />

谢谢!

【问题讨论】:

    标签: android android-layout layout android-fragments android-relativelayout


    【解决方案1】:

    尝试删除这些。

    android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin"

    他们为 RelativeLayout 添加填充。

    【讨论】:

      【解决方案2】:

      您应该首先删除内边距和边距,以便获得简单的布局。 ok的时候可以把padding&margin一个一个放回去,看看哪个ok。

      【讨论】:

        【解决方案3】:

        从按钮父布局中删除填充,然后您的按钮将与屏幕边缘对齐。

        <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:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.abushawish.randommovie.MainActivity$PlaceholderFragment" >
        

        如果您仍想为其他对象添加内边距,请将它们添加到带有内边距的单独布局中。

        编辑

        要将图片放在中间添加

        android:layout_centerHorizontal="true"
        

        【讨论】:

          【解决方案4】:

          尝试 android:gravity="bottom" 并在相关布局中添加 android:layout_alignParentBottom="true"

          【讨论】:

            【解决方案5】:

            这将为您提供预期的外观.. 是的,不要给 RelativeLayout 的孩子看重

            <Button
                android:id="@+id/button1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:text="New Movie Suggestion" />
            

            【讨论】:

              猜你喜欢
              • 2012-03-08
              • 2013-07-14
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多