屏幕底部的定位按钮
Positionning button from bottom screen
我正在为 android 应用做一些 XML。
我的视图中有图片、文本和按钮。
我使用了线性布局,但我认为这不是我需要的。
我想将最后一个按钮设置为距离底部屏幕 80 dp。无论智能手机和屏幕大小如何。
我希望我的按钮距离所有设备底部 80 dp。
我不知道该怎么做,如果有人能帮助我,那就太好了!
我试过使用 LinearLayout,但我想我做不到。
现在我正在尝试使用 constraintLayout,但不确定它是否有效。
谢谢
这是使用相对布局作为父级实现目标的方法之一:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bottom Button"
android:layout_alignParentBottom="true"
android:layout_marginBottom="80dp"/>
</RelativeLayout>
你可以用 RelativeLayout
和 layout_alignParentBottom
看看这个:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textview1"/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_below="@+id/textview1"/>
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Button"
android:layout_marginBottom="80dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
在使用此代码之后使用相对布局而不是线性布局作为父布局
ADD Views inside this Relative Layout whatever you want to add like Textview etc.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button at bottom"
android:layout_alignParentBottom="true"
android:layout_marginBottom="80dp"/>
</RelativeLayout>
我终于找到了约束布局的解决方案。
我使用 app:layout_constraintBottom_toBottomOf 将按钮与屏幕底部对齐,然后使用 marginBottom。感谢大家的回复,我会尝试使用相对布局:)
我正在为 android 应用做一些 XML。
我的视图中有图片、文本和按钮。
我使用了线性布局,但我认为这不是我需要的。
我想将最后一个按钮设置为距离底部屏幕 80 dp。无论智能手机和屏幕大小如何。 我希望我的按钮距离所有设备底部 80 dp。
我不知道该怎么做,如果有人能帮助我,那就太好了!
我试过使用 LinearLayout,但我想我做不到。
现在我正在尝试使用 constraintLayout,但不确定它是否有效。
谢谢
这是使用相对布局作为父级实现目标的方法之一:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bottom Button"
android:layout_alignParentBottom="true"
android:layout_marginBottom="80dp"/>
</RelativeLayout>
你可以用 RelativeLayout
和 layout_alignParentBottom
看看这个:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textview1"/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_below="@+id/textview1"/>
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Button"
android:layout_marginBottom="80dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
在使用此代码之后使用相对布局而不是线性布局作为父布局 ADD Views inside this Relative Layout whatever you want to add like Textview etc.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button at bottom"
android:layout_alignParentBottom="true"
android:layout_marginBottom="80dp"/>
</RelativeLayout>
我终于找到了约束布局的解决方案。
我使用 app:layout_constraintBottom_toBottomOf 将按钮与屏幕底部对齐,然后使用 marginBottom。感谢大家的回复,我会尝试使用相对布局:)