对齐屏幕底部1/3处的按钮

时间:2016-10-14 14:05:06

标签: java android android-layout

我试图在屏幕底部对齐一个按钮,但距离底线稍远一点。我怎样才能做到这一点?我已经尝试过垂直和水平对中按钮并且它可以正常工作,但我需要将按钮移动到中心下方或略低于底线。

enter image description here

我需要移动" PLAY"按钮在屏幕上稍微低一些。另外,我还需要将按钮缩小一点,以达到其当前尺寸的80%。我怎么能这样做?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="acevix.gladiators3.MainActivity">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:srcCompat="@drawable/splash"
    android:id="@+id/imageView"
    android:scaleType="centerCrop"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:adjustViewBounds="true" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_marginBottom="50dp"
    android:id="@+id/button3"
    android:background="@drawable/play" />

</RelativeLayout>

2 个答案:

答案 0 :(得分:1)

使用此代码,

<强>机器人:layout_alignParentBottom = “真”
机器人:layout_centerHorizo​​ntal = “真”
机器人:layout_marginBottom = “30DP”

试试这个;

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="30dp"/>

</RelativeLayout>

更新代码

使用此: android:layout_below

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/logo"
        android:layout_width="200dp"
        android:layout_height="80dp"
        android:layout_centerInParent="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/logo"
        android:layout_centerInParent="true"
        android:layout_marginTop="30dp" />

</RelativeLayout>

答案 1 :(得分:0)

您可以使用不同的屏幕分辨率 intuit/sdp

将此行添加到 gradle文件

编译'com.intuit.sdp:sdp-android:1.0.3'