在屏幕底部下方对齐一个按钮
Align a button below the bottom of the screen
目前我的代码在屏幕底部放置了一个按钮:
<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%)。最终,我的最终结果是,当我点击并向上拖动按钮时,它会向上移动并显示整个按钮,但在此之前,它的底部被剪掉了。
有很多关于如何将按钮对齐到屏幕底部的问题,但我似乎找不到任何可以将其对齐到屏幕底部下方的问题。
有什么方法可以做到这一点,还是我没有使用正确的搜索词?
编辑:根据答案,我尝试了 android:translationY="20dp" 但它不起作用,但我尝试了 android:layout_marginBottom="-20dp" 并且对我有用。
您可以翻译按钮:
android:translationY="20dp"
在您的 xml 中,这会将视图向下移动 20 dp。
您可以将 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>
目前我的代码在屏幕底部放置了一个按钮:
<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%)。最终,我的最终结果是,当我点击并向上拖动按钮时,它会向上移动并显示整个按钮,但在此之前,它的底部被剪掉了。
有很多关于如何将按钮对齐到屏幕底部的问题,但我似乎找不到任何可以将其对齐到屏幕底部下方的问题。
有什么方法可以做到这一点,还是我没有使用正确的搜索词?
编辑:根据答案,我尝试了 android:translationY="20dp" 但它不起作用,但我尝试了 android:layout_marginBottom="-20dp" 并且对我有用。
您可以翻译按钮:
android:translationY="20dp"
在您的 xml 中,这会将视图向下移动 20 dp。
您可以将 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>