Fragments ConstraintLayout is cut of in FrameLayout of activity - android

I have an activity LoginActivity and a fragment SignupSocialFragment.
The fragment is loaded inside of the FrameLayout inside the activity.
The problem is, that the LinearLayout (social_login_footer) in fragment which is constrained to the bottom of its parent is cut of when the fragment is displayed in the activity.
When I add padding/margin to the social_login_footerI can shift it into view but this does not work reliable.
Can anyone help with why the bottom part is cut of?
Shouldnt the ConstraintLayout match the height of its parent FrameLayout.
Code
activity_login.xml
<?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:id="#+id/login_constraint"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorBlack"
tools:context=".ui.login.LoginActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/login_constraint_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.airbnb.lottie.LottieAnimationView
android:id="#+id/login_lottie_animation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lottie_autoPlay="true"
app:lottie_fileName="background_rotation.json"
app:lottie_loop="true" />
</androidx.constraintlayout.widget.ConstraintLayout>
<ImageView
android:id="#+id/login_logo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:scaleType="centerInside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.050000012"
app:srcCompat="#drawable/logo_white" />
<TextView
android:id="#+id/login_logo_subtitle"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="#string/slogan"
android:textColor="#color/colorWhite"
android:textSize="16sp"
android:translationY="-10dp"
app:layout_constraintEnd_toEndOf="#+id/login_logo"
app:layout_constraintStart_toStartOf="#+id/login_logo"
app:layout_constraintTop_toBottomOf="#id/login_logo" />
<FrameLayout
android:id="#+id/login_content"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
app:layout_constraintTop_toBottomOf="#+id/login_logo_subtitle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
fragment_login_social.xml
<?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="#300000CC "
android:paddingStart="32dp"
android:paddingEnd="32dp"
tools:context=".ui.login.SignupSocialFragment">
<TextView
android:id="#+id/login_social_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="32dp"
android:fontFamily="#font/montserrat_light"
android:text="#string/login_subtitle"
android:textAlignment="center"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="#+id/social_login_email"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/social_login_email"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="#string/email_signup_btn"
app:layout_constraintBottom_toTopOf="#+id/social_login_facebook"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/login_social_text" />
<Button
android:id="#+id/social_login_facebook"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="8dp"
app:icon="#drawable/facebook_logo"
app:iconGravity="textStart"
app:layout_constraintBottom_toTopOf="#+id/social_login_google"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/social_login_email" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/social_login_google"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_marginTop="16dp"
android:background="#color/colorWhite"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/social_login_facebook">
<TextView
android:id="#+id/social_login_google_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="#string/google_signup_btn"
android:textColor="#android:color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/social_login_google_logo"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="8dp"
android:src="#drawable/googleg_standard_color_18"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/social_login_google_txt"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="#+id/social_login_member"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:padding="4dp"
android:text="#string/already_member"
android:textSize="16sp"
android:clickable="true"
android:focusable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/social_login_google" />
<LinearLayout
android:id="#+id/social_login_footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<TextView
android:id="#+id/login_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_version"
android:layout_marginEnd="4dp"
android:textSize="12sp" />
<TextView
android:id="#+id/login_policy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="#string/privacy_link"
android:textSize="12sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Layout blueprints
Rendered on Nexus 5X API 28

After wasting some hours of my precious lifetime I have finally found it.
The problem is caused by the ImageViews android:adjustViewBounds="true" attribute.
After removing it everything works as expected.

Try adding android:fitsSystemWindows="true" to fragment_login_social.xml first child view

Related

How do I properly push a layout upwards when using a Snackbar in Android?

I'm trying to implement a proper snackbar that doesn't overlap other views, to do that I added to the activity a Coordinator Layout and inside I placed a constraint layout with the views I want to be pushed up. In the constraint layout I set the attribute app:layout_dodgeInsetEdges="bottom" but when the snackbar appears it pushes the views upwards but it is a little glitchy, here is the video:
video
The video is of an emulator but the same thing happens on real phones.
<?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"
tools:context=".login.LoginActivity">
<ImageView
android:id="#+id/login_logo"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_marginStart="80dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="80dp"
android:contentDescription="#string/logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/google_logo" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/loginCoordinatorLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/login_outwire_logo">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/innerConstraintlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_dodgeInsetEdges="bottom">
<LinearLayout
android:id="#+id/create_account_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginBottom="16dp"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/facebook_sign_button">
<TextView
android:id="#+id/dont_have_account_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:text="#string/don_t_have_an_account"
android:textSize="#dimen/subTextSize" />
<TextView
android:id="#+id/create_account_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:text="#string/create_account"
android:textColor="#color/clickable_subtext_blue"
android:textSize="#dimen/subTextSize" />
</LinearLayout>
<EditText
android:id="#+id/login_user_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:autofillHints="Username, Email"
android:ems="14"
android:hint="#string/email_username"
android:inputType="text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="TextFields" />
<EditText
android:id="#+id/login_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autofillHints="Password"
android:ems="14"
android:hint="#string/password"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/login_user_email" />
<com.app.custom.views.SignInButton
android:id="#+id/sign_in_button"
android:layout_width="#dimen/sign_button_width"
android:layout_height="#dimen/sign_button_height"
android:layout_marginTop="48dp"
android:background="#drawable/sign_in_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/login_password"
app:text="#string/sign_in"
app:text_color="?attr/colorOnPrimary"
app:text_size="#dimen/sign_button_text" />
<TextView
android:id="#+id/forgot_password_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:clickable="true"
android:elevation="2dp"
android:focusable="true"
android:text="#string/forgot_your_password"
android:textColor="#color/clickable_subtext_blue"
android:textSize="#dimen/subTextSize"
app:layout_constraintEnd_toEndOf="#+id/login_password"
app:layout_constraintTop_toBottomOf="#+id/login_password" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/or_sign_in_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.6"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="#+id/google_sign_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/sign_in_button">
<View
android:id="#+id/separator"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="#color/separator_grey"
android:contentDescription="#string/sign_in_options_separator"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/or_sign_in_with_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/or_sign_in_with_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/or_sign_in_with"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="#+id/separator2"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="#color/separator_grey"
android:contentDescription="#string/sign_in_options_separator"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/or_sign_in_with_text"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.app.custom.views.SignInButton
android:id="#+id/google_sign_button"
android:layout_width="#dimen/sign_button_width"
android:layout_height="#dimen/sign_button_height"
android:layout_marginTop="64dp"
android:backgroundTint="?attr/colorSecondary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/sign_in_button"
app:src_logo="#drawable/google_logo"
app:text="#string/google"
app:text_color="?attr/colorOnSecondary" />
<com.app.custom.views.SignInButton
android:id="#+id/facebook_sign_button"
android:layout_width="#dimen/sign_button_width"
android:layout_height="#dimen/sign_button_height"
android:layout_marginTop="8dp"
android:backgroundTint="#color/facebook_blue"
android:clickable="true"
android:focusable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/google_sign_button"
app:src_logo="#drawable/fb_logo"
app:text="#string/facebook"
app:text_size="#dimen/sign_button_text"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

how to make a constraint layout scrollable

Hello I'm trying to make one of my fragment's layout scrollable but can't reach my goal despite having looking for a solution during many hours. I removed all of the layout_constraintBottom_toBottomOf="parent" constraints inside the main constraint layout and also set the height of the layout to wrap_content. Finally I set the fillViewPort attribute of the scrollView to true but the result remains the same. Can someone help me please ?
Here's my .xml file :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ProgressBar
android:id="#+id/challengeProgressBar"
style="#android:style/Widget.DeviceDefault.Light.ProgressBar.Large"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="300dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/errorImageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="300dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/visibleLayout"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/profileNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/profileImageView" />
<ImageView
android:id="#+id/profileImageView"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginStart="143dp"
android:layout_marginTop="45dp"
android:layout_marginEnd="143dp"
android:padding="5dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="#tools:sample/avatars" />
<TextView
android:id="#+id/uploadStatusTextView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
app:layout_constraintBottom_toTopOf="#+id/profileImageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/nbPointsTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:textAppearance="#style/TextAppearance.AppCompat.Display1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/profileNameTextView" />
<Button
android:id="#+id/completedChallengesButton"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginStart="75dp"
android:layout_marginTop="52dp"
android:layout_marginEnd="75dp"
android:text="#string/completed_challenges"
android:textSize="10sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/nbPointsTextView" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/completedChallengesRecyclerView"
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_marginStart="75dp"
android:layout_marginEnd="75dp"
android:background="#drawable/border"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/completedChallengesButton" />
<Button
android:id="#+id/challengesButton"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginStart="75dp"
android:layout_marginEnd="75dp"
android:text="#string/current_challenges"
android:textSize="10sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/completedChallengesRecyclerView" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/challengesRecyclerView"
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_marginStart="75dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="75dp"
android:background="#drawable/border"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/challengesButton" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
The cause is using scrollable view (RecyclerView) inside ScrollView, so you should put this one to your RecyclerView
android:nestedScrollingEnabled="false"
But the better solution is make whole screen into only one RecyclerView

how to make progress bar always in the center screen of scroll view and swipe refresh layout?

I have views hierarchy like this:
and here is my xml:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/constraintLayout_profile">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" android:id="#+id/swipeRefreshLayout_userControl">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#android:color/white"
android:id="#+id/scrollView_user_control"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imageView_profile_image_user_information"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/user"
app:civ_border_width="0.5dp"
app:civ_border_color="#FF000000" android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginStart="8dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="16dp" app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:text="User Fullname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView_user_fullname_user_information" android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/imageView_profile_image_user_information"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp"
android:textSize="18sp"/>
<TextView
android:text="user#email.com"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView_user_email_user_information" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp"
app:layout_constraintTop_toBottomOf="#+id/textView_user_fullname_user_information"
android:layout_marginTop="8dp"/>
<TextView
android:text="AKAN DIHADIRI"
android:layout_width="0dp"
android:layout_height="35dp"
android:id="#+id/textView_will_come_user_information" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/textView_user_email_user_information"
android:gravity="center|left"
android:paddingStart="16dp" android:background="#D2D1D6"/>
<ImageView
android:src="#drawable/ic_settings"
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView_gear_setting_user_information"
app:layout_constraintTop_toTopOf="#+id/imageView_profile_image_user_information"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="24dp"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:layout_constraintTop_toBottomOf="#+id/textView_will_come_user_information"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:listitem="#layout/item_general_event"
android:id="#+id/recyclerView_attended_event_user_control"
app:layout_constraintHorizontal_bias="1.0"
android:nestedScrollingEnabled="false">
</androidx.recyclerview.widget.RecyclerView>
<ImageView
android:id="#+id/imageView_verified_icon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="4dp"
app:layout_constraintEnd_toEndOf="#+id/imageView_profile_image_user_information"
app:layout_constraintTop_toTopOf="#+id/imageView_profile_image_user_information"
app:srcCompat="#drawable/verifiedicon" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
<ProgressBar
android:id="#+id/progressBar_user_control"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
as you can see, there is recycler view inside my scroll view, and also there is a swipe refresh layout wrap it all.
I want my progress bar will always be in the center of the screen. I have tried to read from here: How to make a ProgressBar stay in the center of screen despite scrolling . it is said that
You need the ScrollView to be at same level as ProgressDialog in your
Layout
I have tried to implement that, like the image above, but I don't know why my progress bar will not appear in the screen.
if I put the progress bar inside the scroll view like this:
the progress bar will appear, but not in the center of the screen. it depends of the number of items inside my recycler view. so how to solve this ?
Place your ProgressBar at the bottom of outer ConstraintLayout. Check below:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/constraintLayout_profile">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" android:id="#+id/swipeRefreshLayout_userControl">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#android:color/white"
android:id="#+id/scrollView_user_control"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imageView_profile_image_user_information"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/user"
app:civ_border_width="0.5dp"
app:civ_border_color="#FF000000" android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginStart="8dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="16dp" app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:text="User Fullname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView_user_fullname_user_information" android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/imageView_profile_image_user_information"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp"
android:textSize="18sp"/>
<TextView
android:text="user#email.com"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView_user_email_user_information" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp"
app:layout_constraintTop_toBottomOf="#+id/textView_user_fullname_user_information"
android:layout_marginTop="8dp"/>
<TextView
android:text="AKAN DIHADIRI"
android:layout_width="0dp"
android:layout_height="35dp"
android:id="#+id/textView_will_come_user_information" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/textView_user_email_user_information"
android:gravity="center|left"
android:paddingStart="16dp" android:background="#D2D1D6"/>
<ImageView
android:src="#drawable/ic_settings"
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView_gear_setting_user_information"
app:layout_constraintTop_toTopOf="#+id/imageView_profile_image_user_information"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="24dp"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:layout_constraintTop_toBottomOf="#+id/textView_will_come_user_information"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:listitem="#layout/item_general_event"
android:id="#+id/recyclerView_attended_event_user_control"
app:layout_constraintHorizontal_bias="1.0"
android:nestedScrollingEnabled="false">
</androidx.recyclerview.widget.RecyclerView>
<ImageView
android:id="#+id/imageView_verified_icon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="4dp"
app:layout_constraintEnd_toEndOf="#+id/imageView_profile_image_user_information"
app:layout_constraintTop_toTopOf="#+id/imageView_profile_image_user_information"
app:srcCompat="#drawable/verifiedicon" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<ProgressBar
android:id="#+id/progressBar_user_control"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>

View Pager not scrolling in a scrollView

I'm having a ViewPager and a RecyclerView in layout file. I want to make the entire layout Scrollable. That is i want the ViewPager to be scrolled up. Hence, i added <ScrollView> as the root layout.
Issue:
The problem i'm facing is that the RecyclerView in scrolling as expected, but the ViewPager area is fixed.
The Below Image depicts the issue mentioned above:
The xml code of my layout file is as shown below:
<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:orientation="vertical"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.Guideline
android:id="#+id/home_viewpager_guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.4" />
<androidx.viewpager.widget.ViewPager
android:id="#+id/home_view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/home_viewpager_guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/home_viewpager_dots_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="#+id/home_viewpager_guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"></LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#color/latest_news_bg"
app:layout_constraintBottom_toTopOf="#+id/latest_news_guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/home_view_pager">
<View
android:id="#+id/divider2"
android:layout_width="0dp"
android:layout_height="3dp"
android:background="#color/gray"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.16"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="1.0" />
<TextView
android:id="#+id/latest_news_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:text="Latest News"
android:textColor="#color/dark_gray"
android:textSize="22sp"
app:layout_constraintBottom_toTopOf="#+id/divider2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/latest_news_guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.51" />
<TextView
android:id="#+id/home_article_type_txt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:fontFamily="sans-serif-medium"
android:text="Featured Article"
android:textColor="#color/pf_white"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="#+id/home_viewpager_dots_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.02"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.65" />
<TextView
android:id="#+id/home_article_title_txt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="8dp"
android:text="What better way to put your health and wellbeing first than"
android:textColor="#color/pf_white"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/home_viewpager_dots_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.05"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/home_article_type_txt"
app:layout_constraintVertical_bias="0.0" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/home_article_list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout3"
app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
What have i tried?
As mentioned in this answer Android ScrollView not Scrolling
, i have tried setting the ScrollView orientation to vertical and fillViewPort property to true, but the problem still persists.
I have also tried using NestedScrollView as the root, but that too didn't work.
If someone can suggest me how to go about with this, it will be really helpful to anyone facing such issue.

Items in Recyclerview adapter jumps to right after i click a button

I have a scrollview as the root layout for my fragment and in that scrollview there is a linearlayout which inside has a constraintlayout and a recyclerview, and there are 2 columns in my recyclerview. When my fragment launches , The UI is fine but when i click on a button a column jumps towards the right side of the screen. im not adding any marginlayout to right or left so I don't know why this is happening. Didn't have this issue before, I am facing this issue after using scrollview. I have pasted the code below. Any ideas as to why the columns change after clicking on a button.
As far as I think, this is an issue with the linear layout because it was fine before I used that.
Fragment xml:
<?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="scoutingFragmentViewModel"
type="com.resatech.android.navigationtest.viewModels.ScoutingFragmentViewModel">
</variable>
</data>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:fadeScrollbars="false"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:focusableInTouchMode="true">
<android.support.constraint.ConstraintLayout
android:id="#+id/constraint_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image_bg"
android:layout_width="385dp"
android:layout_height="285dp"
android:src="#color/cpb_grey"
android:visibility="visible"
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"
app:layout_constraintVertical_bias="1.0" />
<TextView
android:id="#+id/text_scout_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Scouting Timer"
android:textColor="#color/color_text_dark"
android:textSize="20sp"
android:visibility="#{scoutingFragmentViewModel.mScoutingTimerTextVisibility}"
app:layout_constraintBottom_toBottomOf="#+id/image_bg"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.474"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.335" />
<Button
android:id="#+id/button_ready"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="92dp"
android:layout_marginEnd="30dp"
android:background="#drawable/connect_button"
android:text="Ready"
android:visibility="#{scoutingFragmentViewModel.mReadyButtonVisibility}"
app:layout_constraintEnd_toEndOf="#+id/image_bg"
app:layout_constraintHorizontal_bias="0.484"
app:layout_constraintStart_toStartOf="#+id/image_bg"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button_stop_scouting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="#drawable/connect_button"
android:text="Stop Scouting"
android:visibility="#{scoutingFragmentViewModel.mStopScoutingButtonVisibility}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.31" />
<Button
android:id="#+id/button_connect"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_marginStart="8dp"
android:layout_marginTop="88dp"
android:layout_marginEnd="8dp"
android:background="#drawable/connect_button"
android:shadowColor="#A84F4F"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="0"
android:text="Connect"
android:textColor="#140533"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.443"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="500dp"
>
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</ScrollView>
</layout>
Itemlist xml:
<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
<variable
name="itemGridViewModel"
type="com.resatech.android.navigationtest.viewModels.ItemGridViewAdapterViewModel" />
</data>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/layout_border"
android:maxWidth="150dp"
android:maxHeight="150dp"
android:layout_marginTop="20dp"
android:paddingVertical="10dp"
app:cardBackgroundColor="#ffffff">
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/big_text"
android:layout_width="60dp"
android:layout_height="69dp"
android:layout_marginStart="20dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="21dp"
android:layout_marginBottom="16dp"
android:text="#{itemGridViewModel.values}"
android:textSize="50sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.51"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.526" />
<TextView
android:id="#+id/small_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="21dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="1dp"
android:text="#{itemGridViewModel.description}"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.468"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/big_text" />
<ImageView
android:id="#+id/image"
android:layout_width="23dp"
android:layout_height="22dp"
android:layout_marginEnd="50dp"
android:layout_marginBottom="50dp"
app:imageResource="#{itemGridViewModel.imageNames}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.05"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.077" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</layout>
Display:
try add android:clickable="true" this line into ScrollView
android:clickable="true"
Try to used Recyclerview and set GridLayoutManger and define columns like this way..
recyclerview.setLayoutManager(new GridLayoutManager(this,2,LinearLayoutManager.VERTICAL,false));

Categories

Resources