I'm pulling data from firebase into a recyclerview. When I add the recycleView.setHasFixedSize(true); my app doesnt crash but nothing appears. When I get rid of this line my data appears but all the content in touching and the cardview is shrinking to suit the data. Is there any solutions to this?
Edit:
This is the CardView:
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/eventParent"
android:layout_width="240dp"
android:layout_height="300dp"
android:background="#drawable/border_style"
android:layout_marginRight="24dp"
android:paddingRight="24dp"
android:orientation="vertical"
>
<ImageView
android:layout_width="110dp"
android:layout_height="70dp"
android:layout_marginLeft="70dp"
android:background="#drawable/bgitemcustom"
android:scaleType="centerCrop"
android:src="#drawable/crash" />
<TextView
android:id="#+id/make"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginRight="10dp"
android:lineSpacingExtra="8dp"
android:text="Mercedes"
android:textAlignment="center"
android:textSize="22sp" />
<TextView
android:id="#+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginRight="10dp"
android:lineSpacingExtra="8dp"
android:text="Saloon"
android:textAlignment="center"
android:textSize="22sp" />
<TextView
android:id="#+id/year"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginRight="10dp"
android:lineSpacingExtra="8dp"
android:text="2004"
android:textAlignment="center"
android:textSize="22sp" />
<Button
android:id="#+id/connect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Connect"
android:textSize="14sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
This is where i am creating the recylerview. Its the first one i'm using with the id:eventsplace:
<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:orientation="vertical" android:layout_width="match_parent"
android:background="#drawable/blue"
android:layout_height="match_parent">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="#string/title"
android:textAlignment="center"
android:textColor="#color/yellow"
android:textSize="25sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/eventsplace"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="20dp"
android:clipToPadding="false"
android:paddingRight="250dp"
app:layout_constraintBottom_toTopOf="#id/contacts"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/title"
app:layout_constraintVertical_bias="0.0">
</androidx.recyclerview.widget.RecyclerView>
<TextView
android:id="#+id/contacts"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginBottom="368dp"
android:text="Contacts"
android:textColor="#color/yellow"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="#id/contacts"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/eventsplace"
app:layout_constraintVertical_bias="1.0" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/contactsView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingBottom="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/contacts"
app:layout_constraintVertical_bias="0.069">
</androidx.recyclerview.widget.RecyclerView>
</androidx.constraintlayout.widget.ConstraintLayout>```
After trying out different approaches, the issue is because the item layout does not fit within the recycler layout.
Here are a few solutions :
Set the height of your CardView to wrap_content
Set a fixed height for the layout_height of recycler view in constraint layout instead of wrap_content
Related
I am working on a UI, in which I have to take email and number from user, buttons should must be at bottom, after button, there is a footer too on bottom. I have to make it responsive. I am using scroll view for this purpose. I am stuck on a point.
I am using wrap_content as height for a view, and giving its top to bottom of upper view, and its bottom to top of lower view's top. On small screens, it is working fine, but due to these constraints, on large screens, it is in the centre of screen.
Please have a look on it:
<?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"
android:background="#color/white"
android:orientation="vertical">
<ScrollView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#id/footer"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginBottom="6dp"
android:scrollbars="none"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="0dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/icon_img"
android:layout_width="wrap_content"
android:layout_height="230dp"
android:layout_marginHorizontal="10dp"
android:layout_marginTop="18dp"
android:src="#drawable/ic_sample"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/loginTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/icon_img"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:fontFamily="#font/exo_light"
android:gravity="start"
android:text="Login"
android:textColor="#color/charcol_blue"
android:textSize="22sp"
app:layout_constraintTop_toBottomOf="#id/icon_img" />
<TextView
android:id="#+id/login_Desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/loginTxt"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="20dp"
android:fontFamily="#font/exo_regular"
android:gravity="start"
android:text="Enter your credentials"
android:textColor="#color/charcol_blue"
android:textSize="14sp"
app:layout_constraintTop_toBottomOf="#id/loginTxt" />
<EditText
android:id="#+id/loginEditTextEmail"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/login_Desc"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:background="#drawable/rounded_input_shape"
android:fontFamily="#font/exo_regular"
android:hint="Email"
android:inputType="textEmailAddress"
android:paddingStart="25dp"
android:paddingEnd="25dp"
android:textSize="17sp"
app:layout_constraintTop_toBottomOf="#id/login_Desc" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/phone_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="#+id/btnLayout"
app:layout_constraintTop_toBottomOf="#id/loginEditTextEmail">
<androidx.constraintlayout.widget.ConstraintLayout
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginHorizontal="20dp"
android:background="#drawable/rounded_input_shape"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="50dp">
<com.hbb20.CountryCodePicker
android:id="#+id/ccp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#F5F5F5"
android:gravity="center"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:ccp_autoDetectCountry="true"
app:ccp_defaultPhoneCode="41" />
<EditText
android:id="#+id/editText_carrierNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:hint=" Ph Number"
app:layout_constraintLeft_toRightOf="#+id/ccp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="#+id/ccp"
app:layout_constraintBottom_toBottomOf="#+id/ccp"
android:fontFamily="#font/exo_regular"
android:inputType="phone"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textSize="15sp" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/btnLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toBottomOf="parent">
<Button
android:id="#+id/loginBtnSubmit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="20dp"
android:background="#drawable/blue_round_button"
android:fontFamily="#font/exo_regular"
android:padding="10dp"
android:text="#string/login"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="#+id/imageView1"
android:layout_width="0sp"
android:layout_height="0dp"
android:background="#drawable/divider"
app:layout_constraintBottom_toBottomOf="#id/orText"
app:layout_constraintLeft_toLeftOf="#id/loginBtnSubmit"
app:layout_constraintRight_toLeftOf="#id/orText"
app:layout_constraintTop_toTopOf="#+id/orText" />
<TextView
android:id="#+id/orText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="#font/exo_regular"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="OR"
android:textColor="#color/black"
android:textSize="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/loginBtnSubmit" />
<View
android:id="#+id/imageView2"
android:layout_width="0sp"
android:layout_height="0dp"
android:background="#drawable/divider"
app:layout_constraintBottom_toBottomOf="#id/orText"
app:layout_constraintLeft_toRightOf="#id/orText"
app:layout_constraintRight_toRightOf="#id/loginBtnSubmit"
app:layout_constraintTop_toTopOf="#+id/orText" />
<Button
android:id="#+id/guestContinue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="20dp"
android:background="#drawable/white_round_button"
android:fontFamily="#font/exo_regular"
android:padding="10dp"
android:text="Sign Up"
android:textAllCaps="false"
android:textColor="#color/instruction_black_color"
android:textSize="16sp"
app:layout_constraintTop_toBottomOf="#+id/orText" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:fontFamily="#font/exo_regular"
android:text="App "
app:layout_constraintTop_toTopOf="#+id/txt2"
app:layout_constraintBottom_toBottomOf="#+id/txt2"
app:layout_constraintRight_toLeftOf="#+id/txt2"
android:textColor="#color/charcol_blue"
android:textSize="14sp" />
<TextView
android:id="#+id/txt2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginLeft="2dp"
android:fontFamily="#font/exo_regular"
android:gravity="center_vertical"
android:text="Footer"
app:layout_constraintTop_toTopOf="#+id/footerImg"
app:layout_constraintBottom_toBottomOf="#+id/footerImg"
app:layout_constraintRight_toLeftOf="#+id/footerImg"
android:textColor="#color/charcol_blue"
android:textSize="14sp" />
<ImageView
android:id="#+id/footerImg"
android:layout_width="30dp"
android:layout_height="22dp"
android:layout_marginLeft="2dp"
android:scaleType="fitCenter"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:src="#drawable/logout" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
I am facing issue agains a constraint layout whose id is: "phone_layout"
If I will use its height as 0dp, it will works fine on large screens, but on small screens (when scroll view will be used to scroll screen), this layout will not be shown because of 0dp height.
I want this phone_layout to be below of email layout on every screen(small/large).
I resolved it by using
app:layout_constraintVertical_bias="0"
I am trying to create a screen with a complex collapsing toolbar. This is the layout for it
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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/nested_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
tools:context=".view.main.profile.ProfileFragment">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/lighter_gradient_background">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_user_details"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/iv_profile_picture"
android:layout_width="#dimen/profile_image_size"
android:layout_height="#dimen/profile_image_size"
android:layout_marginStart="30dp"
android:layout_marginTop="20dp"
android:adjustViewBounds="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/tv_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="#font/montserrat_medium"
android:paddingBottom="20dp"
android:text="#string/location"
android:textColor="#color/white"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#id/iv_profile_picture"
app:layout_constraintStart_toStartOf="#id/iv_profile_picture"
app:layout_constraintTop_toBottomOf="#id/iv_profile_picture" />
<TextView
android:id="#+id/tv_followers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="80dp"
android:fontFamily="#font/montserrat_medium"
android:text="321"
android:textColor="#color/white"
android:textSize="14sp"
app:layout_constraintStart_toEndOf="#id/iv_profile_picture"
app:layout_constraintTop_toTopOf="#id/iv_profile_picture" />
<TextView
android:id="#+id/tv_followers_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:fontFamily="#font/montserrat_regular"
android:text="#string/followers"
android:textColor="#color/white"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#id/tv_followers"
app:layout_constraintStart_toStartOf="#id/tv_followers"
app:layout_constraintTop_toBottomOf="#id/tv_followers" />
<TextView
android:id="#+id/tv_following"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:fontFamily="#font/montserrat_medium"
android:text="123"
android:textColor="#color/white"
android:textSize="14sp"
app:layout_constraintStart_toEndOf="#id/tv_followers"
app:layout_constraintTop_toTopOf="#id/tv_followers" />
<TextView
android:id="#+id/tv_following_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/montserrat_regular"
android:text="#string/following"
android:textColor="#color/white"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#id/tv_following"
app:layout_constraintStart_toStartOf="#id/tv_following"
app:layout_constraintTop_toTopOf="#id/tv_followers_label" />
<Button
android:id="#+id/btn_edit_profile"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginTop="16dp"
android:background="#drawable/edit_profile_button"
android:fontFamily="#font/poppins_medium"
android:text="#string/edit_profile"
android:textColor="#color/white"
android:textAllCaps="false"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="#id/tv_following_label"
app:layout_constraintStart_toStartOf="#id/tv_followers_label"
app:layout_constraintTop_toBottomOf="#id/tv_followers_label" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
<TextView
android:id="#+id/tv_username"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:fontFamily="#font/montserrat_semibold"
android:text="#string/username"
android:textColor="#color/white"
android:textSize="18sp"/>
<com.google.android.material.tabs.TabLayout
android:id="#+id/tl_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/tab_layout_bottom_border"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/app_bar">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/white"
android:text="#string/activity" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/interests" />
</com.google.android.material.tabs.TabLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_posts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
<View
android:id="#+id/interests_background"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#color/white"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/btn_add_new_interests"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="16dp"
android:background="#drawable/add_interests_profile_button"
android:fontFamily="#font/montserrat_medium"
android:text="#string/add_new_interests"
android:textAllCaps="false"
android:textColor="#color/colorPrimary"
android:textSize="15sp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.chip.ChipGroup
android:id="#+id/cg_interests"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:visibility="gone"
app:chipSpacingVertical="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/btn_add_new_interests" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
The behavior I want to achieve is when a user presses the part of the screen where the RecyclerView is and drags it up, the toolbar should collapse. The behavior that is happening now is that when a user does the above mentioned nothing happens, but when he presses and flicks the RecyclerView, only then does the toolbar collapse. Does anyone know why this is happening? How can it be fixed?
I copied instructions from tutorials and the layout is the same. Also this was implemented in another part of the app and it works well, but that fragment has a smaller simpler header, which doesn't have nested views.
After disabling the nested scroll view with android:nestedScrollingEnabled="false" on the RecyclerView, the layout had the intended behavior
I am trying to create this following screen layout for my movie app:
I created this layout to accomplish it:
<?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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="true"
app:layout_constraintBottom_toTopOf="#+id/ButtonPanel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="25dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="#+id/id_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3">
<TextView
android:id="#+id/identification_label"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="#font/roboto"
android:gravity="bottom"
android:text="Movie Identification"
android:textColor="#color/BaseColor_1"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/edit_identification"
style="#style/IconButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="TODO"
android:src="#drawable/ic_edit_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.55"
app:layout_constraintStart_toStartOf="#id/identification_label"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="226dp" />
<ImageButton
android:id="#+id/help_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_help"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
style="#style/IconButton" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/sample_name_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_light"
android:text="Movie Name"
android:textAlignment="viewStart"
android:textColor="#color/BaseColor_1"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/sample_description_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_light"
android:text="Movie Description"
android:textAlignment="viewStart"
android:textColor="#color/BaseColor_1"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/sample_name_label" />
<ImageButton
android:id="#+id/sample_show_content_description"
style="#style/IconButton"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginStart="10dp"
android:src="#drawable/btn_reveal_sample_description"
app:layout_constraintBottom_toBottomOf="#+id/sample_description_label"
app:layout_constraintStart_toEndOf="#+id/sample_description_label" />
<TextView
android:id="#+id/sample_description_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="#font/roboto_light"
android:maxLines="0"
android:textAlignment="viewStart"
android:textColor="#color/BaseColor_1"
android:textSize="14sp"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/sample_description_label" />
</androidx.constraintlayout.widget.ConstraintLayout>
<View
android:id="#+id/identification_data_divider"
style="#style/Divider" />
</LinearLayout>
<LinearLayout
android:id="#+id/location_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/id_layout">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="40dp">
<TextView
android:id="#+id/location_label"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="#font/roboto"
android:gravity="bottom"
android:text="Other Information"
android:textColor="#color/BaseColor_1"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="#+id/diretor_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_light"
android:text="Director Name"
android:textAlignment="viewStart"
android:textColor="#color/BaseColor_1"
android:textSize="14sp" />
<TextView
android:id="#+id/a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_light"
android:text="Main actor"
android:textAlignment="viewStart"
android:textColor="#color/BaseColor_1"
android:textSize="14sp" />
<TextView
android:id="#+id/b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_light"
android:text="Movie Genre"
android:textAlignment="viewStart"
android:textColor="#color/BaseColor_1"
android:textSize="14sp" />
<TextView
android:id="#+id/f"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_light"
android:text="Critics rating"
android:textAlignment="viewStart"
android:textColor="#color/BaseColor_1"
android:textSize="14sp" />
<View style="#style/Divider" />
</LinearLayout>
<LinearLayout
android:id="#+id/picture_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/location_layout"
app:layout_constraintVertical_bias="1.0">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="40dp">
<TextView
android:id="#+id/picture_label"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="#font/roboto"
android:gravity="bottom"
android:text="#string/sample_images_label"
android:textColor="#color/BaseColor_1"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="5dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/first_picture"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_weight="1"
app:srcCompat="#drawable/outcrop_placeholder" />
<ImageView
android:id="#+id/second_picture"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_weight="1"
app:srcCompat="#drawable/outcrop_placeholder" />
<ImageView
android:id="#+id/third_picture"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_weight="1"
app:srcCompat="#drawable/outcrop_placeholder" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/ButtonPanel"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/BaseColor_4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintVertical_bias="0.0">
<ImageButton
android:id="#+id/delete_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:src="#drawable/btn_delete"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/confirm_button"
app:layout_constraintHorizontal_bias="0.004"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
style="#style/IconButton" />
<Button
android:id="#+id/confirm_button"
android:layout_marginEnd="25dp"
android:text="#string/confirm_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
style="#style/RoundedCornersMaterialButton" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
As you can see I have to set manually the images' layout_height, but I would like to get the best proportion for the pictures (adjust the images 15dp on top of the bottom toolbar). I have tried to use app:layout_constraintBottom_toBottomOf in the LinearLayout that contains these pictures, but when I click on the collpasible and the description is shown I need to scroll through the screen to see the pictures, but using app:layout_constraintBottom_toBottomOf the images simply disappear.
I know that app:layout_constraintBottom_toBottomOf should not be used in this case, but is there any other way to change the layout_height of my pictures to wrap_content and get the best size for them when I have to scroll down?
Basically, I want another option (besides app:layout_constraintBottom_toBottomOf) that will adjust the images 15dp on top of the bottom toolbar when I am scrolling down.
I would really appreciate if someone could help me with this.
Thanks!
I am using RecyclerView and Constraint layout for RecyclerView Item.
I am using two Views in RecyclerView.
1) ItemViewHolder
2) FooterViewHolder
Below is my code for FooterViewHolder layout,
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/world_credits_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textColor="#color/black"
android:textSize="20sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="#+id/description_1_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textColor="#color/black"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="#id/world_credits_description"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="#+id/description_2_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textColor="#color/black"
android:textSize="15sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/description_1_text_view"/>
<Button
android:id="#+id/cost_1_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$10"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.226"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/description_2_text_view" />
<Button
android:id="#+id/cost_2_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$20"
android:layout_marginTop="20dp"
app:layout_constraintStart_toEndOf="#id/cost_1_button"
app:layout_constraintTop_toBottomOf="#id/description_2_text_view"/>
<Button
android:id="#+id/cost_3_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$30"
android:layout_marginTop="20dp"
app:layout_constraintStart_toEndOf="#id/cost_2_button"
app:layout_constraintTop_toBottomOf="#id/description_2_text_view"/>
<Button
android:id="#+id/add_credits_button"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Credits"
app:layout_constraintTop_toBottomOf="#id/cost_1_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<ListView
android:id="#+id/rate_category_details_list_view"
android:layout_width="wrap_content"
android:divider="#null"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/add_credits_button"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Below is a code for ItemViewHolder layout,
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/package_name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="20sp"
android:text="Package Name"
android:layout_marginTop="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/start_guideline"
/>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/start_guideline"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content"
app:layout_constraintGuide_percent="0.05"/>
<TextView
android:id="#+id/subscription_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="14sp"
android:layout_marginTop="10dp"
app:layout_constraintTop_toBottomOf="#id/package_name_text_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="#+id/package_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="15sp"
android:layout_marginTop="15dp"
app:layout_constraintTop_toBottomOf="#id/subscription_text_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<ImageView
android:id="#+id/flag_1"
android:layout_width="40dp"
android:layout_height="40dp"
android:scaleType="fitXY"
android:layout_marginStart="152dp"
android:layout_marginTop="15dp"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/package_description" />
<ImageView
android:id="#+id/flag_2"
android:layout_width="40dp"
android:layout_height="40dp"
android:scaleType="fitXY"
android:layout_marginTop="15dp"
app:layout_constraintStart_toEndOf="#id/flag_1"
app:layout_constraintTop_toBottomOf="#id/package_description"/>
<ImageView
android:id="#+id/flag_3"
android:scaleType="fitXY"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="15dp"
app:layout_constraintStart_toEndOf="#id/flag_2"
app:layout_constraintTop_toBottomOf="#id/package_description"/>
<ImageView
android:id="#+id/show_multiple_countries"
android:scaleType="fitXY"
android:layout_width="25dp"
android:layout_height="25dp"
android:src="#drawable/right"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="#id/package_description"
app:layout_constraintStart_toEndOf="#id/flag_3"
/>
<TextView
android:id="#+id/validity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="25sp"
android:layout_marginTop="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/flag_1"
app:layout_constraintVertical_bias="0.028" />
<Button
android:id="#+id/activate_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#color/nexge_blue"
android:textColor="#color/color_white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/validity_text_view"
app:layout_constraintVertical_bias="0.038" />
<View
android:id="#+id/first_divider"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginTop="15dp"
android:background="#android:color/darker_gray"
app:layout_constraintBottom_toBottomOf="#id/or_text_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/or_text_view"/>
<TextView
android:id="#+id/or_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Or"
android:background="#color/white"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:padding="5dp"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/activate_button" />
</androidx.constraintlayout.widget.ConstraintLayout>
Below code is for RecyclerView,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/show_offer_details_relative_layout"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
>
<TextView
android:id="#+id/no_record_text_view"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:textSize="25sp"
android:layout_height="wrap_content" />
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<include
android:id="#+id/header"
layout="#layout/header_view" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/header" />
</RelativeLayout>
Sometime if I one or two rows are displayed, then while scrolling half of the screen is scrolling.
1) When setting FooterView of RecyclerView, constraint layout height to wrap content, Listview displays only one item.
That's really very bad. Please Anybody help me.Thanks in advance.
change your Recyclerview constraint layout height match_parent to wrap_content
Change FooterViewHolder layout height to wrap contents.
The "match parent" makes it fill the whole display.
I have a scrollview inside ConstraintLayout. but scrollview not working in ConstraintLayout. I tried NestedScrollView instead of ScrollView but it still not working. ScrollView worked fine with LinearLayout or RelativeLayout but in didn't work in ConstraintLayout.I changed android:layout_height to match_parent and wrap_content but it didn't work. what is the problem?
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<include
android:id="#+id/other_toolbar_xml"
layout="#layout/other_toolbar_xml"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#id/other_toolbar_xml"
android:fillViewport="true"
tools:ignore="MissingConstraints"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/img_content_xml"
android:layout_width="match_parent"
android:layout_height="170dp"
app:layout_constraintTop_toBottomOf="#id/other_toolbar_xml"
android:scaleType="fitXY"
tools:ignore="NotSibling"
/>
<TextView
android:id="#+id/title_content_xml"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/img_content_xml"
android:layout_marginRight="16dp"
android:paddingLeft="16dp"
android:textDirection="rtl"
android:text="title"
android:textSize="17sp"
android:textColor="#1d1d1d"
/>
<TextView
android:id="#+id/content_content_xml"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/title_content_xml"
android:layout_marginTop="20dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:paddingLeft="16dp"
android:textDirection="rtl"
android:text="content"
android:textColor="#1d1d1d"
/>
<ImageView
android:id="#+id/img_date_content_Xml"
android:layout_width="18dp"
android:layout_height="18dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/content_content_xml"
android:layout_marginTop="20dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:src="#drawable/date"
/>
<TextView
android:id="#+id/date_content_xml"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/content_content_xml"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintRight_toLeftOf="#id/img_date_content_Xml"
android:layout_marginTop="20dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:text="date"
android:textColor="#1d1d1d"
android:layout_marginBottom="16dp"
/>
<TextView
android:id="#+id/subject_content_xml"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/content_content_xml"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="20dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:singleLine="true"
android:text="subject"
android:textColor="#1d1d1d"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
You missed some constraint to give as you have added tools:ignore="MissingConstraints" in <ScrollView tag.
There are two ways:
Remove Parent Constraint Layout and use RelativeLayout as no need of ConstraintLayout in just two layouts. (It is mostly used for complex view to make it easy)
Give proper constraint if you want to use ConstraintLayout. You missed left, right, bottom constraint as follow:
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="true"
app:layout_constraintTop_toBottomOf="#id/other_toolbar_xml"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" >
//....
</ScrollView>
Firstly if you are using constraintlayout as the parent layout so
you need to constrain child views properly.Scrollview that you have defined is not constrained properly that's why scrollview
doesn't work.
Here is my code:
<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">
<include
android:id="#+id/other_toolbar_xml"
layout="#layout/toolbar_back"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
<ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
android:fillViewport="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/other_toolbar_xml"
tools:ignore="MissingConstraints">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/img_content_xml"
android:layout_width="match_parent"
android:layout_height="170dp"
android:scaleType="fitXY"
app:layout_constraintTop_toBottomOf="#id/other_toolbar_xml"
tools:ignore="NotSibling" />
<TextView
android:id="#+id/title_content_xml"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
android:paddingLeft="16dp"
android:text="title"
android:textColor="#1d1d1d"
android:textDirection="rtl"
android:textSize="17sp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/img_content_xml" />
<TextView
android:id="#+id/content_content_xml"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:paddingLeft="16dp"
android:text="content"
android:textColor="#1d1d1d"
android:textDirection="rtl"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/title_content_xml" />
<ImageView
android:id="#+id/img_date_content_Xml"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:src="#drawable/date"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/content_content_xml" />
<TextView
android:id="#+id/date_content_xml"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="16dp"
android:text="date"
android:textColor="#1d1d1d"
app:layout_constraintRight_toLeftOf="#id/img_date_content_Xml"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/content_content_xml" />
<TextView
android:id="#+id/subject_content_xml"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="20dp"
android:singleLine="true"
android:text="subject"
android:textColor="#1d1d1d"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#id/content_content_xml" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>