Basic coordinator layout causing jittering effect when flinging (as shown in the video)
This effect, apparently only happens on Huawei (Or low end devices in general). Same code working fine on Samsung s7 edge ( and generally high end devices like mine OP6)
I tried altering the scroll flags, but in vain. I also tried to go with the custom behavior route, however, there is no direction for me there. Like I haven't clearly identified the issue (or the bug in the design support library) to work around it with some custom behavior. I have reached some sort of a dead end about this.
Here is the effect in motion:
Edit: Adding xml code
<android.support.design.widget.CoordinatorLayout 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:id="#+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:fitsSystemWindows="false"
android:focusable="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/toolbarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/toolbar_color"
android:elevation="0dp"
app:elevation="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="#color/transparent"
app:expandedTitleGravity="top"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:statusBarScrim="#color/transparent"
app:titleEnabled="false">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="75dp"
android:paddingBottom="0dp"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll">
<TextView
android:id="#+id/textViewRecipeName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="8dp"
android:fontFamily="#string/font_family_regular"
android:textColor="#color/text_color_18"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="#+id/textViewRating"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Greek salad filled filo cupsGreek salad filled filo cups" />
<TextView
android:id="#+id/textViewRecipeCuisines"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginEnd="16dp"
android:ellipsize="end"
android:fontFamily="#string/font_family_regular"
android:maxLines="4"
android:textColor="#color/text_color_19"
android:textSize="12sp"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#id/textViewRecipeName"
app:layout_constraintTop_toBottomOf="#id/textViewRecipeName"
tools:text="Salads - Appetizers" />
<TextView
android:id="#+id/textViewRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:layout_marginEnd="18dp"
android:fontFamily="#string/font_family_medium"
android:letterSpacing="-0.02"
android:textColor="#color/text_color_18"
android:textSize="18sp"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#id/textViewRecipeName"
tools:text="5.0" />
<TextView
android:id="#+id/textViewRatingLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:fontFamily="#string/font_family_regular"
android:text="#string/home_text_rating"
android:textColor="#color/text_grey"
android:textSize="10sp"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="#id/textViewRating"
app:layout_constraintStart_toStartOf="#id/textViewRating"
app:layout_constraintTop_toBottomOf="#id/textViewRating" />
<ImageView
android:id="#+id/imageViewForRecipe"
android:layout_width="0dp"
android:layout_height="183dp"
android:layout_marginStart="18dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="18dp"
android:scaleType="centerCrop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/textViewRecipeCuisines" />
<ImageView
android:id="#+id/imageViewPlayVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="#id/imageViewForRecipe"
app:layout_constraintEnd_toEndOf="#id/imageViewForRecipe"
app:layout_constraintStart_toStartOf="#id/imageViewForRecipe"
app:layout_constraintTop_toTopOf="#id/imageViewForRecipe"
app:srcCompat="#drawable/ic_play_video" />
<TextView
android:id="#+id/textViewPrepTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:layout_marginEnd="18dp"
android:drawableStart="#drawable/ic_prep_time"
android:drawablePadding="6dp"
android:fontFamily="#string/font_family_regular"
android:letterSpacing="0.01"
android:lineSpacingExtra="12sp"
android:textColor="#color/recipeDetailsColor"
android:textSize="12sp"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/imageViewForRecipe"
tools:text="30 min" />
<View
android:id="#+id/divider1"
android:layout_width="1dp"
android:layout_height="8dp"
android:layout_marginEnd="8dp"
android:background="#color/dividerGreyColor"
app:layout_constraintBottom_toBottomOf="#id/textViewPrepTime"
app:layout_constraintEnd_toStartOf="#id/textViewPrepTime"
app:layout_constraintTop_toTopOf="#id/textViewPrepTime" />
<TextView
android:id="#+id/textViewCookTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:layout_marginEnd="4dp"
android:drawableStart="#drawable/ic_cook_time"
android:drawablePadding="6dp"
android:fontFamily="#string/font_family_regular"
android:letterSpacing="0.01"
android:lineSpacingExtra="12sp"
android:textColor="#color/recipeDetailsColor"
android:textSize="12sp"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="#id/divider1"
app:layout_constraintEnd_toStartOf="#id/divider1"
app:layout_constraintTop_toBottomOf="#id/imageViewForRecipe"
tools:text="10 min" />
<View
android:id="#+id/divider2"
android:layout_width="1dp"
android:layout_height="8dp"
android:layout_marginEnd="8dp"
android:background="#color/dividerGreyColor"
app:layout_constraintBottom_toBottomOf="#id/textViewPrepTime"
app:layout_constraintEnd_toStartOf="#id/textViewCookTime"
app:layout_constraintTop_toTopOf="#id/textViewPrepTime" />
<TextView
android:id="#+id/textViewCapacity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:layout_marginEnd="4dp"
android:drawableStart="#drawable/ic_serving"
android:drawablePadding="6dp"
android:fontFamily="#string/font_family_regular"
android:letterSpacing="0.01"
android:lineSpacingExtra="12sp"
android:textColor="#color/recipeDetailsColor"
android:textSize="12sp"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="#id/divider2"
app:layout_constraintEnd_toStartOf="#id/divider2"
app:layout_constraintTop_toBottomOf="#id/imageViewForRecipe"
tools:text="12 pcs" />
<TextView
android:id="#+id/textViewAboutThisRecipeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
android:fontFamily="#string/font_family_medium"
android:letterSpacing="0.01"
android:lineSpacingExtra="10sp"
android:text="#string/about_this_recipe"
android:textColor="#color/text_color_18"
android:textSize="14sp"
android:textStyle="normal"
app:layout_constraintStart_toStartOf="#id/textViewRecipeName"
app:layout_constraintTop_toBottomOf="#id/textViewCapacity" />
<TextView
android:id="#+id/textViewAboutRecipeValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="11dp"
android:ellipsize="end"
android:fontFamily="#string/font_family_regular"
android:letterSpacing="0.02"
android:lineSpacingExtra="10sp"
android:textColor="#color/text_color_19"
android:textSize="13sp"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="#id/textViewRatingLabel"
app:layout_constraintStart_toStartOf="#id/textViewRecipeName"
app:layout_constraintTop_toBottomOf="#id/textViewAboutThisRecipeLabel"
tools:text="A tosty and filling russian main course, rich in flavor. this plate was invented by rubio safona back in the 1950s after he was in france during WWII" />
</android.support.constraint.ConstraintLayout>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="#color/white"
android:gravity="center"
app:layout_collapseMode="pin">
<ImageView
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginEnd="16dp"
app:srcCompat="#drawable/ic_alwadi"
tools:ignore="ContentDescription" />
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="#color/transparent"
android:gravity="top"
android:theme="#style/ToolbarStyle"
app:layout_collapseMode="pin">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:gravity="center_vertical">
<ImageView
android:id="#+id/imageViewFavorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:src="#drawable/ic_heart"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imageViewShare"
android:layout_width="18dp"
android:layout_height="20dp"
android:layout_marginEnd="16dp"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:src="#drawable/ic_share"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imageViewFavorite"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
<TextView
android:id="#+id/textViewNoMenuItems"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:drawableTop="#drawable/group_13"
android:drawablePadding="8dp"
android:text="No Items found!"
android:visibility="gone"
tools:visibility="visible" />
<android.support.design.widget.TabLayout
android:id="#+id/tabLayoutViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="enterAlways"
app:tabIndicatorColor="#color/colorAccent"
app:tabMode="fixed"
app:tabSelectedTextColor="#color/colorAccent"
app:tabTextAppearance="#style/tabLayoutTextAppearance"
app:tabTextColor="#color/tab_layout_normal_text_color" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="#+id/viewPagerIngredientsPrep"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/linearLayoutButtons"
android:layout_marginTop="4dp" />
<LinearLayout
android:id="#+id/linearLayoutButtons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginStart="16dp"
android:layout_marginTop="13dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="19dp"
android:orientation="vertical">
<android.support.design.button.MaterialButton
android:id="#+id/buttonToggleFavorite"
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/add_to_favorites"
android:textAppearance="#style/ButtonTextAppearance" />
<android.support.design.button.MaterialButton
android:id="#+id/buttonRateThisRecipe"
style="#style/Widget.MaterialComponents.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:text="#string/rate_this_recipe_text"
android:textAppearance="#style/ButtonTextAppearance" />
</LinearLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
The reason behind this is because AppBarLayout does not stop fling when we start fling on any other view of CoordinatorLayout. Solution is quite simple: whenever any child view of CoordinatorLayout starts fling, we need to stop the fling of AppBarLayout (code below is for androidx)
class CustomAppBarBehavior : AppBarLayout.Behavior() {
private var overScroller: OverScroller? = null
override fun onNestedPreFling(coordinatorLayout: CoordinatorLayout,
child: AppBarLayout,
target: View,
velocityX: Float,
velocityY: Float): Boolean {
stopAppBarLayoutFling()
return super.onNestedPreFling(coordinatorLayout, child, target, velocityX, velocityY)
}
private fun stopAppBarLayoutFling() {
if (overScroller == null) {
val scrollerField = javaClass.superclass.superclass.superclass.getDeclaredField("scroller")
scrollerField.isAccessible = true
overScroller = scrollerField.get(this) as? OverScroller
}
overScroller?.forceFinished(true)
}
}
In support version 27, finding the scroller via reflection is a bit different:
val scrollerField = javaClass.superclass.superclass.getDeclaredField("mScroller")
Related
When accessing the page using a Bluetooth keyboard, the Android Tablayout along with its content does not get focused.
But when I am using gesture control it is getting the focus and also can access the contents of the TabItem but when accessing with the external keyboard I am not able to get the focus.
Till now, I tried providing the android:nextFocusRight, android:nextFocusForward but there is no luck that the focus is getting navigated to the desired position.
Below is the XML file
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:id="#+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:id="#+id/graphicOverlayContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_qr_gallery"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginTop="10dp"
android:contentDescription="#string/cl_qr_gallery"
android:nextFocusRight="#id/ll_camera_switch_container"
android:nextFocusDown="#id/ll_camera_switch_container"
android:nextFocusForward="#id/ll_camera_switch_container"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/iv_qr_gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_qr_gallery" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_help"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginTop="10dp"
android:contentDescription="#string/cl_help"
android:nextFocusLeft="#id/tabItemBasic"
android:nextFocusRight="#id/cl_cancel"
android:nextFocusDown="#id/cl_cancel"
android:nextFocusForward="#id/cl_cancel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/iv_help"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_information" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.appcompat.widget.LinearLayoutCompat
android:id="#+id/ll_camera_switch_container"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="16dp"
android:focusable="true"
android:gravity="center_vertical|center_horizontal"
android:nextFocusLeft="#id/cl_qr_gallery"
android:nextFocusRight="#id/cl_help"
android:nextFocusDown="#id/cl_help"
android:nextFocusForward="#id/cl_help"
app:layout_constraintBottom_toBottomOf="#id/cl_help"
app:layout_constraintEnd_toStartOf="#id/cl_help"
app:layout_constraintStart_toEndOf="#id/cl_qr_gallery"
app:layout_constraintTop_toTopOf="parent">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="5dp"
android:focusable="true"
app:cardCornerRadius="30dp"
app:cardElevation="5dp"
app:strokeColor="#android:color/transparent"
app:strokeWidth="0dp">
<com.google.android.material.tabs.TabLayout
android:id="#+id/tl_barcode_camera_switch"
android:layout_width="match_parent"
android:layout_height="32dp"
android:backgroundTint="#android:color/white"
app:tabBackground="#drawable/tab_selector"
app:tabGravity="fill"
app:tabIndicatorColor="#android:color/transparent"
app:tabIndicatorHeight="0dp"
app:tabMaxWidth="0dp"
app:tabMode="fixed"
app:tabRippleColor="#android:color/transparent"
app:tabSelectedTextColor="#android:color/white"
app:tabTextAppearance="#style/QRCodeSwitchTabLayout"
app:tabTextColor="#color/gray1">
<com.google.android.material.tabs.TabItem
android:id="#+id/tabItemAdvanced"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="Advanced View"
android:focusable="true"
android:importantForAccessibility="yes"
android:nextFocusLeft="#id/cl_qr_gallery"
android:nextFocusRight="#id/tabItemBasic"
android:nextFocusForward="#id/tabItemBasic"
android:text="#string/advanced" />
<com.google.android.material.tabs.TabItem
android:id="#+id/tabItemBasic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="Basic View"
android:focusable="true"
android:importantForAccessibility="yes"
android:nextFocusLeft="#id/tabItemAdvanced"
android:nextFocusRight="#id/cl_help"
android:nextFocusForward="#id/cl_help"
android:text="#string/basic" />
</com.google.android.material.tabs.TabLayout>
</androidx.cardview.widget.CardView>
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_cancel"
android:layout_width="0dp"
android:layout_height="60dp"
android:contentDescription="Cancel Button"
android:importantForAccessibility="yes"
android:nextFocusUp="#id/cl_qr_gallery"
android:nextFocusForward="#id/cl_qr_gallery"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/btn_cancel"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="30dp"
android:background="#drawable/bg_qr_code"
android:focusable="false"
android:fontFamily="#font/roboto_medium"
android:importantForAccessibility="no"
android:stateListAnimator="#null"
android:text="#string/cancel"
android:textAllCaps="false"
android:textColor="#android:color/white"
android:textSize="16sp"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tv_barcode_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/darker_gray"
android:ellipsize="end"
android:fadingEdge="horizontal|vertical"
android:fontFamily="#font/roboto"
android:gravity="center_vertical|center_horizontal"
android:maxWidth="400dp"
android:maxLines="3"
android:padding="5dp"
android:textColor="#color/cardview_light_background"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
What I want to achieve is that the cardview is also scrolled up, when the recyclerview (In my xml it's just framelayout but I will later replace it) is scrolled. It is easier to understand with the 2 pictures below.
Not Scrolled
After Scrolling
As you can see from the second picture, the user profile cardview lingers, while I expect it to be scrolled up.
Another problem is that between toolbar and the cardview, there is an empty space line, which you can see in the first picture. I don't know how to remove that.
And the toolbar is also not showing the title, which is set programmatically. No idea why.
This is the xml file. Thanks in advance!
<android.support.design.widget.CoordinatorLayout
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:layout_margin="0dp"
android:fitsSystemWindows="true"
app:statusBarBackground="#android:color/transparent">
<android.support.design.widget.AppBarLayout
android:id="#+id/up_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:layout_marginBottom="0dp"
android:elevation="4dp"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/up_ctoolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:collapsedTitleGravity="center"
app:contentScrim="#android:color/transparent"
app:expandedTitleGravity="center"
app:layout_behavior="#string/title_activity_scrolling"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:titleEnabled="true"
app:toolbarId="#+id/up_toolbar">
<ImageView
android:id="#+id/up_header"
android:layout_width="match_parent"
android:layout_height="#dimen/header_height"
android:background="#drawable/nav_background"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="#+id/up_toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/button_size"
app:contentInsetStart="0dp"
app:layout_collapseMode="pin">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="#+id/up_back"
android:layout_width="#dimen/button_size"
android:layout_height="#dimen/button_size"
android:background="#android:color/transparent"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_back_white" />
<ImageButton
android:id="#+id/up_search"
android:layout_width="#dimen/button_size"
android:layout_height="#dimen/button_size"
android:background="#android:color/transparent"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_search_white" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:layout_marginBottom="16dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/up_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="0dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/up_usericon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:clickable="true"
android:src="#android:drawable/sym_def_app_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/up_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:maxLines="1"
android:text="Username"
android:textColor="#color/BlackGray"
android:textSize="19sp"
app:layout_constraintStart_toStartOf="#+id/up_usericon"
app:layout_constraintTop_toBottomOf="#+id/up_usericon" />
<TextView
android:id="#+id/up_user_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="#10000000"
app:layout_constraintStart_toStartOf="#+id/up_username"
app:layout_constraintTop_toBottomOf="#+id/up_username" />
<TextView
android:id="#+id/up_intro"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:text="Intro: "
android:textColor="#color/BlackGray"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="#+id/up_user_number"
app:layout_constraintTop_toBottomOf="#+id/up_user_number" />
<TextView
android:id="#+id/up_followers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="28dp"
android:clickable="true"
android:text="Followers: 0"
app:layout_constraintBottom_toBottomOf="#+id/up_following"
app:layout_constraintStart_toEndOf="#+id/up_following" />
<TextView
android:id="#+id/up_following"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:clickable="true"
android:text="Following: 0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="#+id/up_intro"
app:layout_constraintTop_toBottomOf="#+id/up_intro" />
<ImageButton
android:id="#+id/up_message"
android:layout_width="#dimen/button_size"
android:layout_height="#dimen/button_size_small"
android:layout_marginEnd="16dp"
android:background="#drawable/button_border_green"
app:layout_constraintEnd_toStartOf="#+id/up_follow"
app:layout_constraintTop_toTopOf="#+id/up_follow"
app:srcCompat="#drawable/ic_mail" />
<ImageButton
android:id="#+id/up_follow"
android:layout_width="#dimen/button_size"
android:layout_height="#dimen/button_size_small"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="#drawable/button_border_orange"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_follow" />
<ImageButton
android:id="#+id/up_edit"
android:layout_width="#dimen/button_size"
android:layout_height="#dimen/button_size_small"
android:layout_marginEnd="16dp"
android:background="#drawable/button_border_orange"
app:layout_constraintEnd_toStartOf="#+id/up_message"
app:layout_constraintTop_toTopOf="#+id/up_message"
app:srcCompat="#drawable/ic_edit" />
<ImageView
android:id="#+id/up_gender"
android:layout_width="#dimen/icon_size_small"
android:layout_height="#dimen/icon_size_small"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="#+id/up_user_number"
app:layout_constraintStart_toEndOf="#+id/up_user_number"
app:layout_constraintTop_toTopOf="#+id/up_user_number"
app:srcCompat="#drawable/ic_male" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.constraint.ConstraintLayout
android:id="#+id/posts_sort_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<TextView
android:id="#+id/up_posts"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:gravity="center_vertical"
android:text="Posts: 0"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<Button
android:id="#+id/up_sortby_button"
style="#style/Widget.AppCompat.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:background="#android:color/transparent"
android:drawableRight="#drawable/ic_down_blue"
android:text="#string/sort_by"
android:textAllCaps="false"
android:textColor="#color/design_default_color_primary"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
<FrameLayout
android:id="#+id/up_timeline"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
The collapse functioning of the toolbar is working well but the effect is very bad and it jitters while expanding and collapsing. Below is my layout code. Even sometimes the toolbar becomes quite big. I have used a custom view instead of an image in this code. The custom view is constraint Layout. The particular code inside a fragment and the fragment consists of tab layout that has a recyclerview in it. I have used parallax effect for the custom view so I am not quite sure about it.
<android.support.design.widget.CoordinatorLayout
tools:context=".ProfileFragment"
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_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<!--this is the collapse mode-->
<android.support.design.widget.AppBarLayout
android:id="#+id/htab_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorAccent"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:elevation="1dp">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="304dp"
android:background="#color/white"
android:fitsSystemWindows="true"
app:contentScrim="#color/colorAccent"
app:expandedTitleTextAppearance="#style/TransparentText"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:title="paco">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="parallax"
android:fitsSystemWindows="true"
android:scaleType="centerCrop">
<android.support.constraint.ConstraintLayout
android:id="#+id/parentLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
>
<!-- TODO: Update blank fragment layout -->
<ImageView
android:id="#+id/profileImage"
android:layout_width="87dp"
android:layout_height="87dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:contentDescription="Profile Image"
android:src="#drawable/capture"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/editImage"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginLeft="100dp"
android:layout_marginStart="100dp"
android:contentDescription="TODO"
app:layout_constraintStart_toEndOf="#+id/profileImage"
app:layout_constraintTop_toTopOf="#+id/profileImage"
app:srcCompat="#drawable/ic_baseline_launch_24px" />
<TextView
android:id="#+id/artistName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="7dp"
android:text="Paco Pardesi"
android:textColor="#333333"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#+id/profileImage"
app:layout_constraintStart_toStartOf="#+id/profileImage"
app:layout_constraintTop_toBottomOf="#+id/profileImage" />
<TextView
android:id="#+id/country"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:text="India"
android:textColor="#757575"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#+id/artistName"
app:layout_constraintStart_toStartOf="#+id/artistName"
app:layout_constraintTop_toBottomOf="#+id/artistName" />
<TextView
android:id="#+id/descriptionArtist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginStart="2dp"
android:layout_marginTop="12dp"
android:text="Artist from the paradise on earth, Kashmir. I like to create art that is about freedom and fresh thinking."
android:textColor="#323232"
android:textSize="13sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/country" />
<android.support.constraint.ConstraintLayout
android:id="#+id/textviewLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="48dp"
android:layout_marginLeft="48dp"
android:layout_marginRight="48dp"
android:layout_marginStart="48dp"
android:layout_marginTop="17dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/descriptionArtist">
<TextView
android:id="#+id/uploadCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1233"
android:textColor="#bea57c"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#+id/Uploads"
app:layout_constraintStart_toStartOf="#+id/Uploads"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/Uploads"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:layout_marginStart="32dp"
android:text="Uploads"
android:textColor="#333333"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/uploadCount" />
<TextView
android:id="#+id/createdCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4567"
android:textColor="#bea57c"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#+id/created"
app:layout_constraintStart_toStartOf="#+id/created"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/created"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:layout_marginStart="32dp"
android:text="Created"
android:textColor="#333333"
android:textSize="14sp"
app:layout_constraintStart_toEndOf="#+id/Uploads"
app:layout_constraintTop_toBottomOf="#+id/createdCount" />
<TextView
android:id="#+id/likesCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8000"
android:textColor="#bea57c"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#+id/likes"
app:layout_constraintStart_toStartOf="#+id/likes"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/likes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:layout_marginStart="32dp"
android:text="Likes"
android:textColor="#333333"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/created"
app:layout_constraintTop_toBottomOf="#+id/likesCount" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</FrameLayout>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0"
android:background="#android:color/black"
android:fitsSystemWindows="true"/>
<android.support.v7.widget.Toolbar
android:id="#+id/htab_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="top"
android:layout_marginBottom="48dp"
app:layout_collapseMode="pin"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="#+id/result_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/colorNormal"
app:tabBackground="#drawable/tab_selector"
app:tabIndicatorColor="#f6f6f6"
app:tabIndicatorHeight="0dp"
app:tabMode="fixed"
app:tabTextColor="#333333" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>
Try adding all custom components which are currently present inside CollapsingToolbarLayout into a separate layout file. Then use
<include layout="#layout/my_custom_layout"/>.
Don't know why but works for me somehow. See if this works for you.
I have the following layout in my android app but I have a problem with windowSoftInputMode="adjustResize" in the activity. The layout contains a next button at the bottom of the screen. When the keyboard is opened, the button is overlapping the input fields instead of collapsing the toolbar.
I've tried
adding android:fitsSystemWindows="true" to the parent layout
setting adjustPan in the manifest
wrapping the constraintlayout and button in a nestedscrollview
wrapping the coordinatorlayout in a Relativelayout
Read:
adjustResize does not work with CoordinatorLayout
Coordinatorlayout adjustresize not working
Remarks:
The funny thing is, when I'm typing something in the first EditText field, when the text goes past the default width, only then it does resize the toolbar and collapses it.
<RelativeLayout 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.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/save_button">
<include layout="#layout/layout_toolbar" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<TextView
android:id="#+id/report_input_name_hint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:fontFamily="#font/customfont"
android:text="#string/report_phonenumber_name_hint"
android:textColor="#color/light_grey"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/report_input_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:background="#android:color/transparent"
android:fontFamily="#font/customfont"
android:hint="#string/report_phonenumber_name_hint"
android:inputType="textPersonName"
android:maxLength="120"
android:textColorHint="#color/text_color_hint"
android:textSize="#dimen/text_18sp"
app:layout_constraintEnd_toStartOf="#+id/clear_text_button_name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/report_input_name_hint" />
<ImageView
android:id="#+id/clear_text_button_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:contentDescription="#string/accessibility_image_description_clear_text_button"
android:padding="#dimen/linespace_10dp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="#+id/report_input_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/report_input_name"
app:srcCompat="#drawable/icn_pro_cross" />
<View
android:id="#+id/textview_underline_name"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:background="#color/light_grey"
app:layout_constraintEnd_toEndOf="#+id/clear_text_button_name"
app:layout_constraintStart_toStartOf="#+id/report_input_name"
app:layout_constraintTop_toBottomOf="#+id/report_input_name" />
<android.support.constraint.Barrier
android:id="#+id/barrier2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="report_input_name,textview_underline_name,clear_text_button_name,report_input_name_hint"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textview_underline_name" />
<TextView
android:id="#+id/report_input_number_hint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:fontFamily="#font/customfont"
android:text="#string/telefoonnummer"
android:textColor="#color/light_grey"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/barrier2" />
<ImageView
android:id="#+id/country_flag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:adjustViewBounds="false"
android:contentDescription="#string/accessibility_image_description_country_flag"
android:padding="#dimen/linespace_10dp"
android:src="#drawable/flag_netherlands"
app:layout_constraintBottom_toBottomOf="#+id/report_input_number"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/report_input_number" />
<ImageView
android:id="#+id/dropdown_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rotation="90"
android:src="#drawable/dropdown_arrow"
app:layout_constraintBottom_toBottomOf="#+id/country_flag"
app:layout_constraintStart_toEndOf="#+id/country_flag"
app:layout_constraintTop_toTopOf="#+id/country_flag"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/country_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:fontFamily="#font/customfont"
android:text="#string/report_phone_dutch_country_code"
android:textColor="#color/dark_text"
android:textSize="#dimen/text_18sp"
app:layout_constraintBottom_toBottomOf="#+id/report_input_number"
app:layout_constraintStart_toEndOf="#+id/dropdown_arrow"
app:layout_constraintTop_toTopOf="#+id/report_input_number" />
<EditText
android:id="#+id/report_input_number"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#android:color/transparent"
android:focusable="true"
android:fontFamily="#font/customfont"
android:hint="#string/report_phone_text_hint"
android:inputType="number"
android:maxLength="13"
android:textColorHint="#color/text_color_hint"
android:textSize="#dimen/text_18sp"
app:layout_constraintEnd_toStartOf="#+id/clear_text_button"
app:layout_constraintStart_toEndOf="#+id/country_code"
app:layout_constraintTop_toBottomOf="#+id/report_input_number_hint" />
<ImageView
android:id="#+id/clear_text_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:contentDescription="#string/accessibility_image_description_clear_text_button"
android:padding="#dimen/linespace_10dp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="#+id/report_input_number"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/report_input_number"
app:srcCompat="#drawable/icn_pro_cross" />
<View
android:id="#+id/textview_underline_number"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:background="#color/light_grey"
app:layout_constraintEnd_toEndOf="#+id/clear_text_button"
app:layout_constraintStart_toStartOf="#+id/country_flag"
app:layout_constraintTop_toBottomOf="#+id/report_input_number" />
<TextView
android:id="#+id/error_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:paddingBottom="#dimen/activity_vertical_margin"
android:textColor="#color/emergency_button_color"
app:layout_constraintEnd_toEndOf="#+id/textview_underline_number"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="#+id/textview_underline_number"
app:layout_constraintTop_toBottomOf="#+id/textview_underline_number" />
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>
<Button
android:id="#+id/save_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="#dimen/activity_horizontal_margin"
android:background="#drawable/report_next_button_background"
android:enabled="false"
android:text="#string/melden_input_volgende"
android:textAllCaps="false"
android:textColor="#color/inactive_text"
android:textSize="#dimen/text_16sp"
android:textStyle="bold" />
Desired result on smaller devices when there is not enough room to display the input fields + button under the expanded toolbar:
Currently I have a very hacky solution which is by far from optimal. I would gladly hear if anyone has a better solution. I figured out that the toolbar won't collapse since the view that is focussed, is already visible. So now i programmatically switch focus to the last item and back to the first item to collapse the toolbar.
report_input_number.requestFocus()
Handler().postDelayed( {
report_input_name.requestFocus()
}, 350)
I'm using the following layout:
<LinearLayout 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:gravity="center|bottom"
android:orientation="vertical">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<include layout="#layout/layout_toolbar" />
<android.support.v4.widget.NestedScrollView
android:id="#+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp">
<TextView
android:id="#+id/report_input_name_hint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:text="#string/report_phonenumber_name_hint"
android:textColor="#color/light_grey"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/report_input_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:background="#android:color/transparent"
android:hint="#string/report_phonenumber_name_hint"
android:inputType="textPersonName"
android:maxLength="120"
android:textColorHint="#color/text_color_hint"
android:textSize="#dimen/text_18sp"
app:layout_constraintEnd_toStartOf="#+id/clear_text_button_name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/report_input_name_hint" />
<ImageView
android:id="#+id/clear_text_button_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:contentDescription="#string/accessibility_image_description_clear_text_button"
android:padding="#dimen/linespace_10dp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="#+id/report_input_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/report_input_name"
app:srcCompat="#drawable/icn_pro_cross" />
<View
android:id="#+id/textview_underline_name"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:background="#color/light_grey"
app:layout_constraintEnd_toEndOf="#+id/clear_text_button_name"
app:layout_constraintStart_toStartOf="#+id/report_input_name"
app:layout_constraintTop_toBottomOf="#+id/report_input_name" />
<TextView
android:id="#+id/report_input_number_hint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="#string/telefoonnummer"
android:textColor="#color/light_grey"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textview_underline_name" />
<ImageView
android:id="#+id/country_flag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:adjustViewBounds="false"
android:contentDescription="#string/accessibility_image_description_country_flag"
android:padding="#dimen/linespace_10dp"
android:src="#drawable/flag_netherlands"
app:layout_constraintBottom_toBottomOf="#+id/report_input_number"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/report_input_number" />
<ImageView
android:id="#+id/dropdown_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rotation="90"
android:src="#drawable/dropdown_arrow"
app:layout_constraintBottom_toBottomOf="#+id/country_flag"
app:layout_constraintStart_toEndOf="#+id/country_flag"
app:layout_constraintTop_toTopOf="#+id/country_flag"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/country_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="#string/report_phone_dutch_country_code"
android:textColor="#color/dark_text"
android:textSize="#dimen/text_18sp"
app:layout_constraintBottom_toBottomOf="#+id/report_input_number"
app:layout_constraintStart_toEndOf="#+id/dropdown_arrow"
app:layout_constraintTop_toTopOf="#+id/report_input_number" />
<EditText
android:id="#+id/report_input_number"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#android:color/transparent"
android:focusable="true"
android:hint="#string/report_phone_text_hint"
android:inputType="number"
android:maxLength="13"
android:textColorHint="#color/text_color_hint"
android:textSize="#dimen/text_18sp"
app:layout_constraintEnd_toStartOf="#+id/clear_text_button"
app:layout_constraintStart_toEndOf="#+id/country_code"
app:layout_constraintTop_toBottomOf="#+id/report_input_number_hint" />
<ImageView
android:id="#+id/clear_text_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:contentDescription="#string/accessibility_image_description_clear_text_button"
android:padding="#dimen/linespace_10dp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="#+id/report_input_number"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/report_input_number"
app:srcCompat="#drawable/icn_pro_cross" />
<View
android:id="#+id/textview_underline_number"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:background="#color/light_grey"
app:layout_constraintEnd_toEndOf="#+id/clear_text_button"
app:layout_constraintStart_toStartOf="#+id/country_flag"
app:layout_constraintTop_toBottomOf="#+id/report_input_number" />
<TextView
android:id="#+id/error_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:paddingBottom="#dimen/activity_vertical_margin"
android:textColor="#color/emergency_button_color"
app:layout_constraintEnd_toEndOf="#+id/textview_underline_number"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="#+id/textview_underline_number"
app:layout_constraintTop_toBottomOf="#+id/textview_underline_number" />
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
<Button
android:id="#+id/save_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/activity_horizontal_margin"
android:layout_marginEnd="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_horizontal_margin"
android:layout_weight="0"
android:background="#drawable/report_next_button_background"
android:enabled="false"
android:text="#string/melden_input_volgende"
android:textAllCaps="false"
android:textColor="#color/inactive_text"
android:textSize="#dimen/text_16sp"
android:textStyle="bold" />
</LinearLayout>
You need to set on the CoordinatorLayout:
android:fitsSystemWindows="false"
This value is default true. In your Android Manifest you need to set the following for the Activity related:
windowSoftInputMode="adjustResize"
I found the solution to the question in this article:
https://code.luasoftware.com/tutorials/android/move-layout-when-keyboard-shown/
I know it's been a while since someone wrote on this thread, but since I came along this as well, I wanted to share my results.
Use adjustpan. It will solve your issue.
I need to fill a LinearLayout (child of a ScrollView) with dynamic TextViews.
The problem is that, in my app, the position where the scroll starts is not defined (it changes dynamically while using the app) and I think I've resolved this with layout_constraintTop_toBottomOf.
The main problem is that I need the ScrollView to end at 90dp from the bottom. But I cannot do that with margins (as in my code below) cause it ignores them.
I've also tried padding but doesn't work too.
This is my solution that doesn't work:
<ScrollView
android:id="#+id/scroll_seguiti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="90dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/scroll_view">
<LinearLayout
android:id="#+id/linear_view_seguiti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="90dp"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
I really need that margin cause at the bottom there are some buttons.
As asked, this is my full xml:
<TableLayout
android:id="#+id/tableLayout_seguiti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="25dp"
android:layout_marginBottom="90dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="Cerca utenti da seguire"
android:textSize="20sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp">
<EditText
android:id="#+id/edit_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="Cerca..." />
</TableRow>
</TableLayout>
<ScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="90dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/tableLayout_seguiti">
<LinearLayout
android:id="#+id/linear_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginBottom="90dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/scroll">
<LinearLayout
android:id="#+id/ln_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="8dp"
android:text="Utenti che segui"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="Clicca sul nome degli utenti che desideri seguire o smettere di seguire."
android:textSize="12sp" />
</LinearLayout>
</ScrollView>
<ScrollView
android:id="#+id/scroll_seguiti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="90dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/scroll_view">
<LinearLayout
android:id="#+id/linear_view_seguiti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/btn_mieiPost"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="15dp"
android:text="I miei post"
style="#style/Widget.AppCompat.Button.Colored"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/btn_home"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/btn_seguiti"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginEnd="15dp"
android:layout_marginStart="10dp"
android:text="Seguiti"
style="#style/Widget.AppCompat.Button.Colored"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/btn_home" />
<Button
android:id="#+id/btn_home"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_marginBottom="10dp"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:text="Home"
style="#style/Widget.AppCompat.Button.Colored"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/btn_seguiti"
app:layout_constraintStart_toEndOf="#+id/btn_mieiPost"
app:srcCompat="#android:drawable/ic_menu_gallery" />
you need to set margin only for scroll view. Remove the margin from the linear layout.
Add full viewport: true for scroll view.
make height of scrollView match_parent this may help check below
<ScrollView
android:id="#+id/scroll_seguiti"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="90dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/scroll_view">
<LinearLayout
android:id="#+id/linear_view_seguiti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="90dp"
android:orientation="vertical">
</LinearLayout>