[英]How to place button at the bottom of LinearLayout within a ScrollView
I have created an addview (xml).我创建了一个 addview (xml)。 When I press add button it creates new one inside the LinearLayout.当我按下添加按钮时,它会在 LinearLayout 中创建一个新按钮。 The add button is placed within the same linearLayout.添加按钮放置在相同的线性布局中。 But when I place the add button, it stays at the same position.但是当我放置添加按钮时,它保持在相同的 position。 But I want the button to be at the bottom of the add view.但我希望按钮位于添加视图的底部。 This is my xml.这是我的 xml。
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/banner"
android:layout_above="@+id/linearmenu"
android:layout_centerHorizontal="true">
<LinearLayout
android:id="@+id/linearLayout_addhere"
android:layout_width="match_parent"
android:layout_gravity="top"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/buttonAdd"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="@drawable/add_button_design"
android:drawableRight="@drawable/ic_add_white"
android:paddingHorizontal="7dp"
android:text="추가"
android:textColor="#FFFFFF"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />
</LinearLayout>
</ScrollView>
Try this way using LinearLayout
使用LinearLayout
尝试这种方式
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/linearmenu"
android:layout_below="@+id/banner"
android:layout_centerHorizontal="true"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearLayout_addhere"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1">
</LinearLayout>
<Button
android:id="@+id/buttonAdd"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_gravity="bottom"
android:layout_marginTop="10dp"
android:paddingHorizontal="7dp"
android:text="추가"
android:textColor="#FFFFFF"
android:textSize="18sp" />
</LinearLayout>
</ScrollView>
Try this way using RelativeLayout
使用RelativeLayout
尝试这种方式
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/buttonAdd"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_gravity="bottom"
android:layout_marginTop="10dp"
android:layout_alignParentBottom="true"
android:paddingHorizontal="7dp"
android:text="추가"
android:textColor="#FFFFFF"
android:textSize="18sp" />
</RelativeLayout>
Try this way using ConstraintLayout
使用ConstraintLayout
尝试这种方式
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_above="@+id/linearmenu"
android:layout_below="@+id/banner"
android:layout_centerHorizontal="true"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/buttonAdd"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_gravity="bottom"
android:layout_marginTop="10dp"
android:layout_alignParentBottom="true"
android:paddingHorizontal="7dp"
android:text="추가"
android:textColor="#FFFFFF"
android:textSize="18sp" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.