Recyclerview animation (layout change in size and margins after click) - android

Iam working on an app using recyclerview in which if I click an item, it will change in layout height(view will be visible) and margins changes.
How to animate like google dialer app when I click recent contact will show elevation layout and shrink margins?
I use notifyitemchange(position) and work in animate shift of point (left and top of layout).
but I want to animate shrink layout margins not shift view like google app dialer recent contacts [google app dialer].
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/groups_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="10dp"
android:paddingBottom="180dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
</LinearLayout>
viewholder layout
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="group"
type="com.example.gtt.database.Group" />
<variable
name="clickListener"
type="com.example.gtt.start.GroupListener" />
<variable
name="viewModel"
type="com.example.gtt.start.StartViewModel" />
</data>
<androidx.cardview.widget.CardView
android:id="#+id/cardView"
layoutMarginGroup="#{group}"
layoutMarginGroupId="#{viewModel.hideShowId}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
app:cardCornerRadius="6dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/itemLayout"
layoutBackColor="#{group}"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:onClick="#{() -> viewModel.onGroupHideShowClicked(group.groupId)}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/groupView"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginStart="#dimen/layoutMargin"
android:layout_marginTop="#dimen/layoutMargin"
android:layout_marginBottom="#dimen/layoutMargin"
android:background="#drawable/colored_circle"
android:gravity="center_horizontal|center_vertical"
android:onClick="#{() -> clickListener.onClick(group)}"
android:text="#{group.groupName.length >=2 ? group.groupName.substring(0,2).toUpperCase() : group.groupName.toUpperCase() }"
android:textAppearance="#style/TextAppearance.AppCompat.Display1"
android:textColor="#color/white"
app:layout_constraintEnd_toStartOf="#id/groupsTextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- android:text="#string/g" -->
<TextView
android:id="#+id/groupsTextView"
groupNameText="#{group}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:textColor="#color/colorBlue"
android:textSize="22sp"
app:layout_constraintBottom_toTopOf="#id/materialTextView"
app:layout_constraintEnd_toStartOf="#+id/cml"
app:layout_constraintStart_toEndOf="#id/groupView"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/materialTextView"
groupMaterialText="#{group}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#color/colorBlue"
android:textSize="22sp"
app:layout_constraintBottom_toTopOf="#id/appTextView"
app:layout_constraintEnd_toEndOf="#id/groupsTextView"
app:layout_constraintStart_toStartOf="#id/groupsTextView"
app:layout_constraintTop_toBottomOf="#+id/groupsTextView" />
<TextView
android:id="#+id/appTextView"
appText="#{group}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:textColor="#color/colorBlue"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="#+id/groupsTextView"
app:layout_constraintStart_toStartOf="#id/groupsTextView"
app:layout_constraintTop_toBottomOf="#+id/materialTextView" />
<LinearLayout
android:id="#+id/cml"
cmlBackColor="#{group}"
android:layout_width="wrap_content"
android:minWidth="70dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="#+id/appTextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/groupsTextView"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="#string/numberOfClasses"
android:textAlignment="center"
android:textSize="12sp" />
<TextView
android:id="#+id/classTextView"
classText="#{group}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textAlignment="center"
android:textColor="#color/colorBlue"
android:textSize="18sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="#string/numberOfMonths"
android:textAlignment="center"
android:textSize="12sp" />
<TextView
android:id="#+id/monthTextView"
monthText="#{group}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textAlignment="center"
android:textColor="#color/colorBlue"
android:textSize="18sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout2"
layoutVisibilityGroup="#{group}"
layoutVisibilityGroupId="#{viewModel.hideShowId}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/cLayout">
<!-- android:visibility="gone"
android:background="#drawable/shadow_border"
-->
<View
android:id="#+id/divider9"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="?android:attr/listDivider"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/addClassButton"
style="#style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:drawableTop="#drawable/ic_add_class"
android:onClick="#{() -> viewModel.addClass()}"
android:text="#string/c"
android:textColor="#color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/delClassButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/delClassButton"
style="#style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:drawableTop="#drawable/ic_del_class"
android:onClick="#{() -> viewModel.delClass()}"
android:text="#string/c"
android:textColor="#color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/addClassButton"
app:layout_constraintTop_toTopOf="#+id/addClassButton" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</layout>
binding adapter to change data and layout
#BindingAdapter("layoutVisibilityGroup", "layoutVisibilityGroupId")
fun ConstraintLayout.setLayoutVisibility(item: Group, id: Long) {
visibility = if (item.groupId == id) {
View.VISIBLE
} else {
View.GONE
}
}
#BindingAdapter("layoutMarginGroup","layoutMarginGroupId")
fun setLayoutMargin(view: CardView, item: Group, id: Long) {
if (view.layoutParams is ViewGroup.MarginLayoutParams) {
val p = view.layoutParams as ViewGroup.MarginLayoutParams
if (item.groupId == id) {
val npx = dpToPixel(10f).toInt()
p.setMargins(npx, p.topMargin, npx, p.bottomMargin)
} else {
p.setMargins(0, p.topMargin,0, p.bottomMargin)
}
//view.layoutParams = p
}
view.cardElevation = if (item.groupId == id) {
dpToPixel(8f)
} else {
0f
}
}
and I use this code to animate layout changes
adapter.notifyItemChanged(oldPosition)
adapter.notifyItemChanged(newPosition)

Related

Button Click and Change Text with Sliding Root Navigation Drawer

I am trying to create a logout button on the Sliding Root Navigation which I found here
This is my main activity
class HomeScreenActivity : AppCompatActivity() {
private lateinit var binding: ActivityHomeScreenBinding
private lateinit var leftDrawerBinding: MenuLeftDrawerBinding
private lateinit var homeScreenViewModel: HomeScreenViewModel
private var slidingRootNav: SlidingRootNav? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityHomeScreenBinding.inflate(layoutInflater)
leftDrawerBinding = MenuLeftDrawerBinding.inflate(layoutInflater)
setContentView(binding.root)
setSupportActionBar(binding.slToolbar)
title = ""
slidingRootSetup(savedInstanceState)
setUpBottomNavBar()
homeScreenViewModel = ViewModelProvider(this)[HomeScreenViewModel::class.java]
replaceFragment(InGymFragment())
// leftDrawerBinding.logoutFab.setOnClickListener(listener)
}
// Side Panel
private fun slidingRootSetup(savedInstanceState: Bundle?) {
slidingRootNav = SlidingRootNavBuilder(this)
.withToolbarMenuToggle(binding.slToolbar)
.withMenuOpened(false)
.withGravity(SlideGravity.LEFT)
.withContentClickableWhenMenuOpened(true)
.withSavedState(savedInstanceState)
.withMenuLayout(R.layout.menu_left_drawer)
.inject()
}
private val listener = View.OnClickListener {
when (it.id) {
leftDrawerBinding.logoutFab.id -> logout()
}
}
private fun logout() {
Toast.makeText(this, "logout clicked!", Toast.LENGTH_LONG).show()
// homeScreenViewModel.logoutUser
// startActivity(Intent(this,AuthenticationScreenActivity::class.java))
}
This is the menu left drawer
Screenshot of menu left drawer
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:backgroundTint="#color/colorPrimaryDark"
android:orientation="vertical">
<TextView
android:id="#+id/user_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="20dp"
android:text="#string/name"
android:textSize="40sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingRight="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/user_name">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/current_membership"
android:textSize="25sp" />
<TextView
android:id="#+id/membership_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/temp"
android:textSize="50sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingRight="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/current_membership"
android:textSize="25sp" />
<TextView
android:id="#+id/membership_status2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/temp"
android:textSize="50sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingRight="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/current_membership"
android:textSize="25sp" />
<TextView
android:id="#+id/membership_status3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/temp"
android:textSize="50sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingRight="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/current_membership"
android:textSize="25sp" />
<TextView
android:id="#+id/membership_status4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/temp"
android:textSize="50sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingRight="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout4">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/current_membership"
android:textSize="25sp" />
<TextView
android:id="#+id/membership_status5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/temp"
android:textSize="50sp" />
</LinearLayout>
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="#+id/logout_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:backgroundTint="#color/white"
android:focusableInTouchMode="true"
android:text="#string/logout"
tools:viewBindingType="com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton"
android:textColor="#color/black"
app:icon="#android:drawable/ic_lock_power_off"
app:iconTint="#color/black"
app:layout_constraintBottom_toTopOf="#id/app_version"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="#+id/app_version"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="20dp"
android:text="#string/app_creator_with_version"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
This is the main activity layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.ui.HomeScreenActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/dark_blue">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/rounded_bottom_appbar"
app:elevation="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<androidx.appcompat.widget.Toolbar
android:id="#+id/sl_toolbar"
android:layout_width="match_parent"
android:layout_height="86dp"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
android:id="#+id/id_progress_bar"
android:layout_width="65dp"
android:layout_height="65dp"
android:indeterminateDrawable="#drawable/progress_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_image"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="#drawable/profile"
android:layout_marginStart="8.5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/welcomeMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:text="#string/app_name"
android:textColor="#ECE8E8"
android:textSize="16sp"
app:layout_constraintStart_toEndOf="#+id/profile_image"
app:layout_constraintTop_toTopOf="#+id/profile_image" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/today_s_date"
android:textColor="#FFFFFF"
android:textSize="20sp"
app:layout_constraintStart_toStartOf="#+id/welcomeMessage"
app:layout_constraintTop_toBottomOf="#+id/welcomeMessage" />
<ImageView
android:id="#+id/notificationsImage"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/ic_notification"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/profile_image"
android:contentDescription="#string/notification" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
android:id="#+id/main_frame_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#id/bottom_nav_bar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/appBarLayout" />
<com.ismaeldivita.chipnavigation.ChipNavigationBar
android:id="#+id/bottom_nav_bar"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="bottom"
android:background="#drawable/rounded_top_bottomnav"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:cnb_menuResource="#menu/bottom_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.drawerlayout.widget.DrawerLayout>
I don't know how to add an adapter to this. I tried searching for anyone already done that before but didn't find any clue.
Please See: Adding an android:onClick="logout" with fun logout(view: View) { Toast.makeText(this, "logout clicked via xml!", Toast.LENGTH_LONG).show() } works. But I wish to change the text too how am I suppose to get a hold to it?
You should include some relevant code of what you have tried so far, in order to better understand the question.
Anyway, if I get that correctly you need to add a Button in the menu.xml file, then in your fragment/activity.kt you can set a onClickListener on said button to implement the logic for logging out.

How to use onFocusChangeListener inside a recycler view adapter?

I am currently trying to expand a view when it is focused and contract it when unfocused. But, I am unable to get the events for onFocusChangeListener. I tried adding that for all of the views inside the parent view but that didn't work either. Is there anything like reyclerview takes all the focus changes to itself not allowing its children? This is my item code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_marginBottom="20dp"
app:cardCornerRadius="6dp"
app:cardElevation="3dp">
<LinearLayout
android:id="#+id/selected"
android:layout_width="7dp"
android:layout_height="match_parent"
android:background="#167ED1"
android:orientation="horizontal" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/largeItemView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible"
android:focusable="true"
android:focusableInTouchMode="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#color/primary"
android:alpha="0.5"
app:layout_constraintTop_toTopOf="parent"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">
<EditText
android:id="#+id/questionTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Question"
android:maxLines="1"
android:padding="20dp"
android:theme="#style/SelectedColorBlue"
app:layout_constraintEnd_toStartOf="#+id/settings"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:focusable="true"
android:focusableInTouchMode="true"/>
<ImageView
android:id="#+id/settings"
android:layout_width="23dp"
android:layout_height="23dp"
android:layout_marginHorizontal="10dp"
android:background="?selectableItemBackgroundBorderless"
android:src="#drawable/more_vert"
app:layout_constraintBottom_toBottomOf="#id/questionTitle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#id/questionTitle"
app:tint="#color/white" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/optionsRV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="vertical"
android:padding="10dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toTopOf="#id/addOption"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/questionTitle"
tools:itemCount="2"
tools:listitem="#layout/add_form_option_item" />
<TextView
android:id="#+id/points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="1 Point"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="#id/addOption"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/addOption" />
<TextView
android:id="#+id/editPoints"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="#string/editHtmlUnderline"
android:textColor="#color/primary"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="#+id/points"
app:layout_constraintStart_toEndOf="#+id/points"
app:layout_constraintTop_toTopOf="#+id/points" />
<Button
android:id="#+id/addOption"
android:layout_width="wrap_content"
android:layout_height="57dp"
android:layout_margin="20dp"
android:drawableEnd="#drawable/plus"
android:text="Add Option"
app:cornerRadius="18dp"
app:layout_constraintBottom_toTopOf="#id/required"
app:layout_constraintEnd_toEndOf="parent" />
<ImageView
android:id="#+id/delete"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_margin="10dp"
android:padding="3dp"
android:src="#drawable/delete"
app:layout_constraintBottom_toBottomOf="#+id/required"
app:layout_constraintEnd_toStartOf="#+id/imageView"
app:layout_constraintTop_toTopOf="#+id/required"
app:tint="#color/gray" />
<ImageView
android:id="#+id/imageView"
android:layout_width="1dp"
android:layout_height="35dp"
android:layout_marginHorizontal="10dp"
android:padding="3dp"
android:src="#color/gray"
app:layout_constraintBottom_toBottomOf="#+id/required"
app:layout_constraintEnd_toStartOf="#id/required"
app:layout_constraintTop_toTopOf="#+id/required"
app:tint="#color/gray" />
<CheckBox
android:id="#+id/required"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:buttonTint="#color/primary"
android:checked="true"
android:text="Required"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<androidx.constraintlayout.widget.Group
android:id="#+id/group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="addOption,points,editPoints,delete,imageView,required" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
and this is my code for adding the focus listsner inside the onBIndViewHolder:
binding.largeItemView.setOnFocusChangeListener { _: View, hasFocus: Boolean ->
Toast.makeText(itemView.context,"Focus change $hasFocus", Toast.LENGTH_SHORT).show()
binding.selected.visibility = if(hasFocus) VISIBLE else View.GONE
binding.group.visibility = if(hasFocus) VISIBLE else View.GONE
}
binding.largeItemView.children.forEach {
it.setOnFocusChangeListener { _, hasFocus ->
Toast.makeText(itemView.context,"Focus change $hasFocus", Toast.LENGTH_SHORT).show()
binding.selected.visibility = if(hasFocus) VISIBLE else View.GONE
binding.group.visibility = if(hasFocus) VISIBLE else View.GONE
}
}
and this is my reycler view:
<ScrollView>
<NestedScrollView>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/optionsRV"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:paddingHorizontal="10dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="10"
tools:listitem="#layout/item_question_add_item" />
</NestedScrollView>
</ScrollView>
Thanks in advance

Android how to animate alpha and then translation?

I want to make 2 animations, I have one view that will disappear once its touched(the one with emojis and "How do you feel today?"), with an alpha animation(from 1 to 0 alpha, at the end its visibility will be View.GONE), and then all the other views in the layout should slide up instead of them going up instantly. I have already done the alpha animation, the transition one is the one I can't achieve.
I am using Constraint Layout so what happens is as soon as the first view disappears changing its visibility to GONE, the others move instantly up. I have tried many ways, but I can´t find how to achieve this. I don't know what type of transition or animation should I use.
This is the code I am using fot the alpha animation:
fun hideEmojiView(view: View) {
val fadeOut: Animation = AlphaAnimation(1f, 0f)
fadeOut.interpolator = AccelerateInterpolator()
fadeOut.duration = 500
fadeOut.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationEnd(animation: Animation) {
view.visibility = View.GONE
}
override fun onAnimationRepeat(animation: Animation) {}
override fun onAnimationStart(animation: Animation) {}
})
view.startAnimation(fadeOut)
}
UPDATE: SOLUTION
I ended up making the suggestion #Tenfour04 made. The problem was that I was adding android:animateLayoutChanges="true" to a ScrollView and it needs to be added to a ConstraintLayout, and it needs to be the direct parent of the view you are dissapearing. So here is my Layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
tools:context=".fragments.maincontent.TodayFragment">
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:fontFamily="#font/subtitle_font"
android:text="Upcoming"
android:textColor="#color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/rv_daily_picks" />
<FrameLayout
android:id="#+id/frameLayout7"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="#color/white"
app:layout_constraintBottom_toBottomOf="#+id/textView6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView6"
app:layout_constraintTop_toTopOf="#+id/textView6">
</FrameLayout>
<FrameLayout
android:id="#+id/frameLayout6"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="#color/white"
app:layout_constraintBottom_toBottomOf="#+id/textView5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView5"
app:layout_constraintTop_toTopOf="#+id/textView5">
</FrameLayout>
<TextView
android:id="#+id/tv_welcome"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:fontFamily="#font/title_font"
android:text="Welcome, Sebastián"
android:textColor="#color/white"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:fontFamily="#font/subtitle_font"
android:text="Stories"
android:textColor="#color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/emoji_view" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_stories"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView5">
</androidx.recyclerview.widget.RecyclerView>
<FrameLayout
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="#color/white"
app:layout_constraintBottom_toBottomOf="#+id/textView7"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView7"
app:layout_constraintTop_toTopOf="#+id/textView7">
</FrameLayout>
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:fontFamily="#font/subtitle_font"
android:text="Daily picks"
android:textColor="#color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/rv_stories" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_daily_picks"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView6">
</androidx.recyclerview.widget.RecyclerView>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_upcoming"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView7" />
<ImageView
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/rv_upcoming" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/emoji_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:background="#drawable/round_white_30alpha_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tv_welcome">
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="#font/subtitle_font"
android:text="How do you feel today?"
android:textColor="#color/white"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView13">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/emoji1"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/circle_white"
android:text="😡"
android:textAllCaps="false"
android:textSize="26sp" />
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/emoji2"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/circle_white"
android:text="🙁"
android:textAllCaps="false"
android:textSize="26sp" />
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/emoji3"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/circle_white"
android:text="🤢"
android:textAllCaps="false"
android:textSize="26sp" />
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/emoji4"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/circle_white"
android:text="😃"
android:textAllCaps="false"
android:textSize="26sp" />
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/emoji5"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/circle_white"
android:text="🤩"
android:textAllCaps="false"
android:textSize="26sp" />
</FrameLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
and my code:
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val binding = FragmentTodayBinding.inflate(layoutInflater)
val user = AppController.get<UserModel>(UserModel.key)
binding.tvWelcome.text = "Welcome, " + user!!.name
binding.emoji1.setOnClickListener{ binding.emojiView.visibility = View.GONE }
binding.emoji2.setOnClickListener{ binding.emojiView.visibility = View.GONE }
binding.emoji3.setOnClickListener{ binding.emojiView.visibility = View.GONE }
binding.emoji4.setOnClickListener{ binding.emojiView.visibility = View.GONE }
binding.emoji5.setOnClickListener{ binding.emojiView.visibility = View.GONE }
return binding.root
}

RecyclerView item get deforme as keyboard pop up

I an activity I am using a dialog (which extend DialogFragment), Dialog contains a recycler view (w: match parent,h:200dp) and below recycler view an edit text and button, as soon as edit text is in focus and keyboard pops up the item in recycler view get deformed. dialog root view (card view) has w:match_parent h: wrap_content and list item root view (constraint layout) have w:match_parent h:wrap_content
enter image description here
Dialog :
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="4dp"
app:cardElevation="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="350dp"
android:orientation="vertical">
<TextView
android:id="#+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginStart="20dp"
android:fontFamily="#font/opensans_bold"
android:gravity="center_vertical"
android:text="#string/label_add_remark"
android:textColor="#color/colorPrimary"
android:textSize="16sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/windowBackground" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_revisit_remarks"
android:layout_width="match_parent"
android:layout_height="#dimen/revisit_rv_size"
android:visibility="gone"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="6"
tools:listitem="#layout/layout_remark_item" />
<LinearLayout
android:id="#+id/ll_add_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#drawable/rectangle_grey_border"
android:minWidth="250dp"
android:orientation="horizontal"
android:weightSum="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/rv_remarks">
<EditText
android:id="#+id/et_add_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="10dp"
android:layout_weight="2"
android:background="#null"
android:hint="#string/add_your_comment"
android:inputType="textMultiLine|textCapSentences"
android:minHeight="40dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textColor="#color/primaryTextColor"
android:textColorHint="#color/text_color_light"
android:textSize="12sp" />
</LinearLayout>
<com.google.android.material.button.MaterialButton
android:id="#+id/button_submit"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:backgroundTint="#color/colorPrimary"
android:fontFamily="#font/opensans_bold"
android:text="#string/submit"
android:textAllCaps="false"
android:textColor="#color/white"
android:translationZ="0dp"
app:cornerRadius="4dp"
app:elevation="0dp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
List Item:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<ImageView
android:id="#+id/iv_profile_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="#drawable/image_member_sample" />
<TextView
android:id="#+id/tv_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:ellipsize="end"
android:fontFamily="#font/opensans_semibold"
android:lines="1"
android:textColor="#color/text_color_dark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/iv_profile_image"
app:layout_constraintTop_toTopOf="#id/iv_profile_image"
tools:text="BIna Antony Mari Kurian Paulose" />
<TextView
android:id="#+id/tv_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginEnd="20dp"
android:fontFamily="#font/opensans_regular"
android:textColor="#color/text_color_dark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#id/tv_name"
app:layout_constraintTop_toBottomOf="#id/tv_name"
tools:text="#tools:sample/lorem" />
</androidx.constraintlayout.widget.ConstraintLayout>
try this:
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

How to scroll scrollView on keyboard shown

I have a scrollView and ConstraintLayout as a child. Inside the constraintLayout, I have at least 2 editTexts.
My layout :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorWhite"
android:descendantFocusability="afterDescendants"
android:fitsSystemWindows="true"
android:focusable="false">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_with_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/status_bar_height"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ScrollView
android:id="#+id/sendScrollView"
android:layout_width="0dp"
android:layout_height="0dp"
android:fillViewport="true"
android:isScrollContainer="false"
android:scrollbars="none"
app:layout_constraintBottom_toTopOf="#id/nextButton"
app:layout_constraintEnd_toEndOf="#id/endGuideline"
app:layout_constraintStart_toStartOf="#id/startGuideline"
app:layout_constraintTop_toBottomOf="#id/toolbar">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="#+id/exchangeCardView"
android:layout_width="#dimen/currency_switch_width"
android:layout_height="#dimen/currency_switch_height"
android:layout_marginTop="#dimen/default_margin"
android:padding="2dp"
app:cardCornerRadius="20dp"
app:cardElevation="#dimen/elevation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ExchangeCurrencyView
android:id="#+id/exchangeSwitchView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.cardview.widget.CardView>
<EditText
android:id="#+id/amountEditText"
style="#style/EditTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/default_margin_x2"
android:autofillHints=""
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:inputType="number|numberDecimal"
android:maxLines="1"
android:minWidth="40dp"
android:singleLine="true"
android:textSize="50sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/exchangeCardView" />
<TextView
android:id="#+id/amountTextView"
style="#style/AmountTextViewStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/amountEditText" />
<TextView
android:id="#+id/balanceTextView"
style="#style/AddressTextViewStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/amountTextView" />
<SidedEditTextView
android:id="#+id/walletAddressEditTextView"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_marginTop="#dimen/default_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/balanceTextView" />
<TextView
android:id="#+id/miningFeesTextView"
style="#style/AddressTextViewStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/default_margin"
android:gravity="center"
android:textColor="#color/feesColor"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/walletAddressEditTextView" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<Button
android:id="#+id/nextButton"
style="#style/RoundButtonStyle"
android:layout_width="0dp"
android:layout_height="#dimen/button_height"
android:layout_marginBottom="#dimen/default_margin_x1"
android:enabled="false"
android:gravity="center"
android:stateListAnimator="#null"
android:text="#string/send"
android:translationZ="#dimen/elevation"
app:elevation="#dimen/elevation"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#id/endGuideline"
app:layout_constraintStart_toStartOf="#id/startGuideline"
app:layout_constraintTop_toBottomOf="#id/sendScrollView" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/startGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.06" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/endGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.94" />
I would like to scroll to the bottom of my scrollView in order to see all inputs above the button.
I used a KeyboardHeightProvider to to do this and it works :
override fun onHeightChanged(height: Int) {
getScrollView()?.let {
when (height) {
0 -> {
it.post {
it.scrollTo(0, 0)
onHide()
}
}
else -> {
it.post {
it.fullScroll(View.FOCUS_DOWN)
}
}
}
}
}
But with this snippet, the keyboard is blinking on screen and I get IInputConnectionWrapper warning.
I tried many other solutions like adding adjustPan or adjustResize but none worked.
android:windowSoftInputMode="adjustResize"
android:fitsSystemWindows="true"
Also, I used this :
val rootView = view?.findViewById<ViewGroup>(android.R.id.content)?.getChildAt(0)
rootView?.let {
it.viewTreeObserver.addOnGlobalLayoutListener {
val diff = it.rootView.height - it.height
if (diff > dpToPx(context!!, 200F)) {
sendScrollView.fullScroll(View.FOCUS_DOWN)
} else {
sendScrollView.fullScroll(View.FOCUS_UP)
}
}
}
Any idea?

Categories

Resources