繁体   English   中英

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

[英]Align button at the bottom 1/3 of the screen

我正在尝试将一个按钮对准屏幕的底部,而不是恰好位于屏幕底部。 我怎样才能做到这一点? 我已经尝试过将按钮垂直和水平居中,并且可以,但是我需要将按钮移到中心下方或底线上方。

在此处输入图片说明

我需要将“播放”按钮移到屏幕下方一点。 此外,我还需要将按钮缩小一点,以使其达到当前大小的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>

使用此代码,

android:layout_alignParentBottom =“ true”
android:layout_centerHorizo​​ntal =“ true”
android: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>

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

将此行添加到您的gradle文件

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM