2016-10-14 83 views
0

我正在嘗試對齊屏幕底部不是右側的按鈕,而是在底線之上的一小段距離處。我怎樣才能做到這一點?我已經嘗試了將按鈕垂直和水平居中並且它可以工作,但是我需要將按鈕移動到中心下方或稍微高於底線。在屏幕底部1/3對齊按鈕

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> 
+0

你試過PercentRelativeLayout? https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html –

+0

我需要在我的RelativeLayout中添加PercentRelativeLayout,我將放置按鈕?對不起,可能愚蠢的問題,我是一個完整的新手 – Radu

+0

你可以顯示你的XML文件請 –

回答

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> 

更新代碼

使用此:機器人: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> 
+0

這工作,謝謝。但我目前正在使用平板電腦進行測試,115dp的marginBottom是完美的。按鈕是否會停留在小屏幕上的相同位置? – Radu

+0

我更新了我的代碼。 –

0

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

這一行添加到您的gradle這個文件

編譯 'com.intuit.sdp:SDP-安卓1.0.3'