2016-06-06 74 views
0

目前我的代码在屏幕的底部放置一个按钮:对齐屏幕的底部下方的按钮

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="bottom" 
    android:layout_alignParentBottom="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:gravity="center|bottom"> 

     <ImageButton 
      android:id="@+id/button1" 
      android:layout_width="95dp" 
      android:layout_height="95dp" 
      android:layout_centerInParent="true" 
      android:gravity="center" 
      android:src="@drawable/main_button" 
      /> 
    </LinearLayout> 
</RelativeLayout> 

不过,我想对齐略低于屏幕的底部,所以小部分按钮被剪掉(比如20%)。最终,我的最终结果是,当我点击并拖动按钮时,它会向上移动并显示整个按钮,但在此之前,它的底部会被裁剪掉。


有关于如何对齐按钮在屏幕的底部了很多问题,但我似乎无法找到任何它对齐到屏幕的底部之下。

有没有办法做到这一点,或者我没有使用正确的搜索条件?


编辑:从答案,我想机器人:translationY =“20dp”,它没有工作,但我想机器人:layout_marginBottom =“ - 20dp”,它为我工作。

+0

如果你可以将其调整的底部,那么你就可以添加上边距来推动它关闭屏幕 –

回答

1

您可以将android:translationY="Xdp"添加到您的按钮以将其向下移动X dp。您也可以创建两个LinearLayouts。一个填满屏幕并保持其他组件,另一个包含按钮。然后,您可以添加android:layout_below="@id/layout0"android:margin_top="Xdp"来控制按钮的布局应该在屏幕下方多远。

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="bottom" 
    android:layout_alignParentBottom="true"> 

     </LinearLayout android:id="@+id/layout0" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:layout_below="@id/layout0" 
      android:margin_top="Xdp" 
      android:gravity="center|bottom"> 

       <ImageButton 
        android:id="@+id/button1" 
        android:layout_width="95dp" 
        android:layout_height="95dp" 
        android:layout_centerInParent="true" 
        android:gravity="center" 
        android:src="@drawable/main_button"/> 
     </LinearLayout> 
</RelativeLayout> 
0

可以转换按钮:

android:translationY="20dp" 
在XML

,这是移动视点20 DP的下降。