I have created an addview (xml). When I press add button it creates new one inside the LinearLayout. The add button is placed within the same linearLayout. But when I place the add button, it stays at the same position. But I want the button to be at the bottom of the add view. This is my 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
<?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
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
<?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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.