How make layout scrollable when softKeyBoard hides buttons and other elements [ANDROID] - java

my goal is to make login ui with footer text, also page should be scrollable whenever content wont show on a view.
I add scroll view in my layout but, when keyboard appears scroll doesn't works anyn suggestions ? those doesn't work, I don't want that button appears above the keyboard
android:windowSoftInputMode="stateHidden|adjustPan"
android:windowSoftInputMode="stateHidden|adjustResize"
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".auth.AuthFragment">
<androidx.core.widget.NestedScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toTopOf="#id/footer">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/authConstraint"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/usernameInputLayout"
android:layout_width="384dp"
android:layout_height="75dp">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/usernameInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<com.google.android.material.button.MaterialButton
android:id="#+id/uSubmit"
android:layout_width="match_parent"
app:layout_constraintTop_toBottomOf="#+id/usernameInputLayout" />
<com.google.android.material.button.MaterialButton
android:id="#+id/uRegistration"
android:layout_width="match_parent"
android:layout_height="70dp"
android:backgroundTint="#2C2C2E"
android:text="SIGNIN"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/uSubmit"
app:layout_constraintStart_toStartOf="#+id/uSubmit"
app:layout_constraintTop_toBottomOf="#+id/uSubmit" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
<FrameLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#color/black"
app:layout_constraintBottom_toBottomOf="#+id/scroll"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="358dp"
android:layout_height="wrap_content"
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

<LinearLayout
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"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#id/view_1"
...
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="#id/view_2"
...
app:layout_constraintTop_toBottomOf="#id/view_1" />
<View
android:id="#id/view_3"
...
app:layout_constraintTop_toBottomOf="#id/view_2" />
<View
android:id="#id/view_4"
...
app:layout_constraintTop_toBottomOf="#id/view_3"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
Make sure you have constraints between all views, parent top and parent bottom.
From my example you can see constraints PARENT_TOP <- View 1 <- View 2 <- View 3 <- View 4 -> PARENT_BOTTOM

Related

Set view to be at bottom of camera preview?

I'd like to set the position of the TextView to always be at the bottom of the camera preview.
This is not the case with my layout below. When the user changes the aspect the ratio of the camera preview (ex: from 16:9 to 4:3), the TextView remains in the same position and is no longer at the bottom of the preview.
How do I set the position of the TextView to always be at the bottom (left) of the camera preview?
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.activities.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/root"
android:background="#color/black"
tools:context=".ui.activities.MainActivity">
<FrameLayout
android:id="#+id/main_frame"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingTop="8dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/preview_container"
android:layout_height="match_parent"
android:layout_width="match_parent">
<androidx.camera.view.PreviewView
android:id="#+id/preview"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="H,9:16"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="#+id/preview"
android:textColor="#ffffffff"
android:text="Text Test" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Try this:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.activities.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/root"
android:background="#color/black"
android:orientation="vertical"
tools:context=".ui.activities.MainActivity">
<FrameLayout
android:id="#+id/main_frame"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingTop="8dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/preview_container"
android:layout_height="match_parent"
android:layout_width="match_parent">
<androidx.camera.view.PreviewView
android:id="#+id/preview"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="H,9:16"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:textColor="#ffffffff"
android:text="Text Test" />
</FrameLayout>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Sorry i dont have enough reputation for comment so i will try answer directly
This problem occurs because you set your textview bottom to bottom with camera preview while use ConstraintLayout. I can give you two option for solve this,
first change textview from app:layout_constraintBottom_toBottomOf to app:layout_constraintTop_toBottomOf.
Second try for wrap it with linearlayout and set orientation to vertical.

Admob showing only on top of XML

I tried to integrate AdMob into my XML, but it only shows the ad at the top of the application.
Image
In Android Studio, it appears in the correct location:
Android Studio
My XML:
<FrameLayout xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/overlayContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="UselessParent">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary">
<TextView
android:id="#+id/bVersion"
style="#style/FakeSpinner"
android:layout_width="72dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:gravity="center"
android:textStyle="bold"
tools:text="VERSNM" />
<my.app.base.widget.NavFrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<my.app.base.widget.GotoButton
android:id="#+id/bGoto"
style="?actionButtonStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="#dimen/nav_goto_side_margin"
android:layout_marginEnd="#dimen/nav_goto_side_margin"
android:fontFamily="sans-serif-medium"
android:includeFontPadding="false"
android:paddingStart="0dp"
android:paddingEnd="0dp"
android:textSize="16sp"
tools:text="Long Name Of Book 123" />
<ImageButton
android:id="#+id/bLeft"
style="?actionButtonStyle"
android:layout_width="#dimen/nav_prevnext_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:contentDescription="#string/desc_previous_chapter"
android:scaleType="center"
android:src="#drawable/ic_nav_start_light" />
<ImageButton
android:id="#+id/bRight"
style="?actionButtonStyle"
android:layout_width="#dimen/nav_prevnext_width"
android:layout_height="match_parent"
android:layout_gravity="end"
android:contentDescription="#string/desc_next_chapter"
android:padding="16dp"
android:scaleType="center"
android:src="#drawable/ic_nav_end_light" />
</my.app.base.widget.NavFrameLayout>
</androidx.appcompat.widget.Toolbar>
<my.app.base.widget.TwofingerLinearLayout
android:id="#+id/splitRoot"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
tools:ignore="NestedWeights">
<my.app.base.verses.EmptyableRecyclerView
android:id="#+id/lsSplitView0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingStart="#dimen/text_side_padding"
android:paddingEnd="#dimen/text_side_padding"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical" >
</my.app.base.verses.EmptyableRecyclerView>
<my.app.base.widget.LabeledSplitHandleButton
android:id="#+id/splitHandleButton"
android:layout_width="match_parent"
android:layout_height="#dimen/split_handle_thickness"
android:background="#null"
android:visibility="gone" />
<my.app.base.verses.EmptyableRecyclerView
android:id="#+id/lsSplitView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingStart="#dimen/text_side_padding"
android:paddingEnd="#dimen/text_side_padding"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical" />
</my.app.base.widget.TwofingerLinearLayout>
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="FULL_BANNER"
ads:adUnitId="AD-UNIT-ID">
</com.google.android.gms.ads.AdView>
</LinearLayout>
<my.app.base.widget.Floater
android:id="#+id/floater"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:visibility="gone" />
</FrameLayout>
It only appears at the top in the running application, already in Android Studio, it appears in the location I want. How do I leave this AdMob ad at the end as it is in Android Studio?
when using a FrameLayout ViewGroup in android, you have to specify the layout_gravity of its children. if u dont, the frame layout moves the child View to the Top which is the default gravity for the children in a FrameLayout. To correct this all you have to do is
set the layout_gravityof the LinearLayout to bottom just like this
since the LinearLayout is the parent of the admob add this
android:layout_gravity = "bottom" to LinearLayout just after android:orientation = "vertical" or any where you would like it to be within the LinearLayout ViewGroup.

Not able to properly nest GridView inside Cardview

I use a RecyclerView , which renders CardView . This CardView has 2 TextViews and one GridView , The GridView renders CardView (lets call it inside_card )as its child. Now i am unable to change height of this inside_card . Given below is what i want to achieve(Image A) and what i am getting (Image B).
Given Below are my Layouts.
activity_main.xml contains RecylerView
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat 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:orientation="vertical"
tools:context=".Activities.MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</androidx.appcompat.widget.LinearLayoutCompat>
activity_card.xml Contains Layout to be rendered inside RecyclerView
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardBackgroundColor="#AAA"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="4dp"
android:layout_margin="8dp"
android:requiresFadingEdge="vertical">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/proffName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ProfessorName"
android:textAlignment="center"
android:gravity="center_horizontal">
</TextView>
<TextView
android:id="#+id/subjectCode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SemesterName"
android:textAlignment="center"
android:gravity="center_horizontal">
</TextView>
<GridView
android:layout_gravity="center"
android:id="#+id/unitsGrid"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_weight="1"
android:layout_margin="6dp"
android:horizontalSpacing="2dp"
android:numColumns="2"></GridView>
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.appcompat.widget.LinearLayoutCompat>
inside_card.xml contains layout to be rendered inside GridView
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/inside_card"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_margin="8dp"
app:cardCornerRadius="6dp"
app:cardElevation="6dp"
app:cardBackgroundColor="#eeeeee"
>
<TextView
android:textAlignment="center"
android:layout_gravity="center"
android:id="#+id/unitName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="1dp"
android:textColor="#color/cardview_dark_background"
android:textSize="18dp" />
</androidx.cardview.widget.CardView> ```
Change in inside_card.xml
-> Increase the height of card view from 45dp to 120dp, tweak as per requirement
-> Set card elevation 0dp, as in the design A, there is no card elevation.
-> Even I will suggest, don't take card view for this, Just take simple LienarLayout and set a drawable shape with stroke for this. Because Setting border on card view is a little tedious task.
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/inside_card"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_margin="8dp"
app:cardCornerRadius="6dp"
app:cardElevation="0dp"
app:cardBackgroundColor="#eeeeee"
>
<TextView
android:textAlignment="center"
android:layout_gravity="center"
android:id="#+id/unitName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="1dp"
android:textColor="#color/cardview_dark_background"
android:textSize="18dp" />
</androidx.cardview.widget.CardView> `
In your GridView, set vertical spacing too
<GridView
android:layout_gravity="center"
android:id="#+id/unitsGrid"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_weight="1"
android:layout_margin="6dp"
android:horizontalSpacing="15dp"
android:verticalSpacing="15dp"
android:numColumns="2"></GridView>

Android App intellij Layout_marginBottom is adding to top

So I have this code in an XML file:
<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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="500dp"
android:id="#+id/constraintLayout" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_dashboard">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView2">
<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/textView" android:text="#string/Tester" android:layout_alignParentEnd="true"
android:layout_marginEnd="18dp" android:layout_marginStart="10dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="50dp" android:layout_margin="0dp"/>
</RelativeLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
The bottom margin within text view is adding to the top not the bottom, and the text at the bottom of the scroll view gets cut off. Also, when I try to just move the layout instead, if I drag it downward, it moves upward after release, and vice versa for dragging upward. Does anyone know what is happening here???
<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">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:ignore="MissingConstraints"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:text="Tester"
android:layout_marginEnd="18dp" android:layout_marginStart="10dp"
android:layout_marginBottom="50dp" android:layout_margin="0dp"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView2">
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

ScrollView doesn't scroll in a ViewPager

In my app I use a TabLayout under a Toolbar, and a ViewPager filling the rest of the space. I need one of the fragments under the tab to be able to scroll. tried using ScrollView, NestedScrollView and android:fillViewport="true" with no success.
I've looked at other questions about the same problem, tried anything that was suggested in the answers, but they all didn't solve my problem.
the activity that contains the ViewPager's code:
<?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:orientation="vertical"
tools:context=".UserProfile">
<include
android:id="#+id/userToolbar"
layout="#layout/user_info_toolbar_layout" />
<com.google.android.material.tabs.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/userToolbar"
android:background="#android:color/holo_blue_light"
app:tabSelectedTextColor="#android:color/white"
app:tabTextColor="#android:color/black">
<com.google.android.material.tabs.TabItem
android:id="#+id/dashboardTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/dashboard_tab_text_en" />
<com.google.android.material.tabs.TabItem
android:id="#+id/statisticsTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/statistics_tab_text_en" />
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager.widget.ViewPager
android:id="#+id/userInfoViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/tabLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>
the fragment's code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/user_dashboard_fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
tools:context=".Dashboard">
<androidx.constraintlayout.widget.ConstraintLayout
android:padding="40dp"
android:id="#+id/userInfoContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.github.abdularis.civ.CircleImageView
android:id="#+id/userImage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:padding="20dp"
android:scaleType="fitCenter"
android:src="#drawable/male_user_sample1"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/username_sample"
android:textColor="#color/colorPrimaryDark"
android:textSize="30sp"
app:layout_constraintTop_toBottomOf="#id/userImage" />
<com.ramijemli.percentagechartview.PercentageChartView
android:id="#+id/userLevelProgress"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="20dp"
android:outlineAmbientShadowColor="#color/colorPrimary"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/username"
app:pcv_animDuration="1000"
app:pcv_animInterpolator="anticipate_overshoot"
app:pcv_drawBackground="false"
app:pcv_drawBackgroundBar="false"
app:pcv_mode="ring"
app:pcv_orientation="counter_clockwise"
app:pcv_progress="100"
app:pcv_startAngle="270"
app:pcv_textColor="#color/colorPrimary"
app:pcv_textShadowRadius="100"
app:pcv_textSize="50sp" />
<TextView
android:id="#+id/userLevel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/level_sample"
android:textColor="#color/colorPrimary"
android:textSize="40sp"
app:layout_constraintTop_toBottomOf="#id/userLevelProgress" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
I can't find the problem in my code that causes the fragment under the ViewPager being unscrollable.
Rty this
In your ViewPager
<androidx.viewpager.widget.ViewPager
android:id="#+id/userInfoViewPager"
android:layout_width="match_parent"
android:layout_height="0dp" // <- ****
app:layout_constraintBottom_toBottomOf="parent" // <- ****
app:layout_constraintTop_toBottomOf="#id/tablayout"
/>
Then, in fragment xml
<ScrollView
....
android:layout_width="match_parent"
android:layout_height="match_parent" // <- ****
>
<androidx.constraintlayout.widget.ConstraintLayout
android:padding="40dp"
android:id="#+id/userInfoContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" // <- ****
>
it's seems like there some bug with ConstraintLayout inside ScrollView ,Don't forget that If you constraint some view's bottom to constraint layout's bottom. Scrollview could not scroll. Use NestedScrollView with viewport true is working good for me
<android.support.v4.widget.NestedScrollView>
......
......
</android.support.v4.widget.NestedScrollView>

Categories