The content that I am adding in this LinearLayout moves down on the screen when I use layout Behavior even if I add it in the XML : Below is my XML code :
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/constraintLayout"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
android:background="@drawable/bottom_sheet_bg"
tools:context=".AddUPIID">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="@font/poppins_medium"
android:text="Payment methods"
android:textColor="#2D2B32"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="15dp"
android:src="@drawable/chevron_left"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="14dp"
android:paddingTop="19dp"
android:paddingEnd="14dp"
android:paddingBottom="50dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/upi_icon_2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:fontFamily="@font/poppins_bold"
android:gravity="center"
android:letterSpacing="0.07"
android:text="Add UPI ID"
android:textColor="#2E2C8D"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="@+id/imageView"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toTopOf="@+id/imageView" />
<TextView
android:id="@+id/texthead_Enter_UPI"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:fontFamily="@font/poppins"
android:gravity="center_vertical"
android:lineSpacingExtra="-1sp"
android:text="Enter UPI ID"
android:textColor="@android:color/black"
app:layout_constraintStart_toStartOf="@+id/imageView"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<EditText
android:id="@+id/editTextText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edittext_bg"
android:fontFamily="@font/poppins"
android:gravity="center_vertical"
android:hint="Enter UPI Id"
android:inputType="text"
android:padding="8dp"
android:textColorHint="#7F7D83"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/texthead_Enter_UPI"
tools:ignore="TouchTargetSizeCheck" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="5dp"
android:fontFamily="@font/poppins"
android:text="Save UPI ID for future usage"
android:textColor="#2D2B32 "
android:textSize="12sp"
app:layout_constraintStart_toEndOf="@+id/imageView3"
app:layout_constraintTop_toBottomOf="@+id/editTextText" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="16dp"
android:layout_height="16dp"
android:background="@drawable/check_box_bg"
app:layout_constraintBottom_toBottomOf="@+id/textView3"
app:layout_constraintStart_toStartOf="@+id/editTextText"
app:layout_constraintTop_toTopOf="@+id/textView3" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:fontFamily="@font/poppins_medium"
android:gravity="center"
android:text="Secured by "
android:textColor="#888888"
android:textSize="12sp"
app:layout_constraintBottom_toTopOf="@+id/proceedButton"
app:layout_constraintEnd_toEndOf="@+id/cardView"
app:layout_constraintStart_toStartOf="@+id/cardView"
app:layout_constraintTop_toBottomOf="@+id/cardView" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/boxpay_copyright"
app:layout_constraintBottom_toBottomOf="@+id/textView5"
app:layout_constraintStart_toEndOf="@+id/textView5"
app:layout_constraintTop_toTopOf="@+id/textView5" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/proceedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="12dp"
android:fontFamily="@font/poppins_semibold"
android:gravity="center"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:text="Verify and proceed payment"
android:textColor="#ADACB0"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
and here is my BottomSheetFragment Code :
package com.example.tray
import android.graphics.Color
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import com.example.tray.databinding.FragmentAddUPIIDBinding
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
class AddUPIID : BottomSheetDialogFragment() {
private lateinit var binding: FragmentAddUPIIDBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentAddUPIIDBinding.inflate(inflater,container,false)
var checked = false
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
binding.imageView3.setOnClickListener(){
if(!checked) {
binding.imageView3.setImageResource(R.drawable.checkbox)
checked = true
}
else {
binding.imageView3.setImageResource(0)
checked = false
}
}
binding.imageView2.setOnClickListener(){
dismiss()
}
binding.proceedButton.isEnabled = false
binding.editTextText.addTextChangedListener(object : TextWatcher{
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
Log.d("beforeTextChanged",s.toString())
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
val textNow = s.toString()
Log.d("onTextChanged",s.toString())
if(textNow.isNotBlank()){
binding.proceedButton.isEnabled = true
binding.proceedButton.setBackgroundResource(R.drawable.button_bg)
binding.proceedButton.setTextColor(Color.parseColor("#FFFFFF"))
}
}
override fun afterTextChanged(s: Editable?) {
Log.d("afterTextChanged",s.toString())
}
})
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val bottomSheetConstraintLayout = binding.constraintLayout
val bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetConstraintLayout)
}
companion object {
}
}
I tried adding LinearLayout and NestedScrollView also but still the same problem. But when I added layout behavior tag in the grandchild of CoordinatorLayout. The view becomes correct.enter image description here