[英]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="Xdp"
到按钮中,以将其向下移动X dp。
或者,您可以创建两个LinearLayouts
。 一个填充屏幕并容纳其他组件,另一个包含按钮。 然后,您可以添加android:layout_below="@id/layout0"
android:margin_top="Xdp"
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>
您可以翻译按钮:
android:translationY="20dp"
在您的xml中,将视图向下移动20 dp。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.