Navigating from one fragment to another using Fragment manager in kotlin - android

I am trying to navigate from one fragment to another using Fragment Manager but the app exits when the button is clicked. I tried a few solutions from the internet but
I am still not able to figure out why. Please help. Thanks in advance!
Groups.kt => The first fragment
package com.example.groupmail
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
class Groups : Fragment(){
private lateinit var addGroup : ImageView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_group_list, container, false)
val recyclerview = view.findViewById<RecyclerView>(R.id.group_list)
val layoutManager: RecyclerView.LayoutManager = LinearLayoutManager(activity)
recyclerview.setLayoutManager(layoutManager)
recyclerview.setHasFixedSize(true)
/*Dummy data => Remove Later */
val dummyData = arrayListOf<GroupList>()
dummyData.add(GroupList("group1", R.drawable.ic_settings))
dummyData.add(GroupList("group2", R.drawable.ic_settings))
dummyData.add(GroupList("group3", R.drawable.ic_settings))
dummyData.add(GroupList("group4", R.drawable.ic_settings))
/*End of dummy data */
val adapter = GroupListAdapter(dummyData)
recyclerview.setAdapter(adapter)
addGroup = view.findViewById(R.id.addGroupsbtn)
/* Move to next fragment on button click*/
addGroup.setOnClickListener {
val fragment = AddingGroup()
fragmentManager?.beginTransaction()?.replace(R.id.addgroup,AddingGroup())?.commit()
}
return view
}
}
fragment_adding_group.xml => Layout of the second fragment
<?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"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
tools:context=".MainActivity"
android:id="#+id/addgroup">
<TextView
android:id="#+id/title"
android:layout_width="373dp"
android:layout_height="312dp"
android:text="Add a Group"
android:textColor="#000000"
android:textSize="30dp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.703"
tools:ignore="MissingConstraints" />
<TextView
android:id="#+id/NameLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textColor="#636363"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.072"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.858"
tools:ignore="MissingConstraints" />
<EditText
android:id="#+id/group_name"
android:layout_width="339dp"
android:layout_height="48dp"
android:background="#d4d4d4"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="20dp"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.361"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.785"
tools:ignore="MissingConstraints,SpeakableTextPresentCheck" />
<TextView
android:id="#+id/EmailLabel"
android:layout_width="283dp"
android:layout_height="234dp"
android:text="Add Member's Email"
android:textColor="#636363"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.175"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.566"
tools:ignore="MissingConstraints" />
<EditText
android:id="#+id/member_email"
android:layout_width="340dp"
android:layout_height="48dp"
android:background="#d4d4d4"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="20dp"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.309"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.644"
tools:ignore="MissingConstraints,SpeakableTextPresentCheck" />
<Button
android:id="#+id/btn_submit"
android:layout_width="337dp"
android:layout_height="48dp"
android:text="Add Group"
android:textAllCaps="false"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.519"
tools:ignore="MissingConstraints" />
<ImageView
android:id="#+id/imageAdd1"
android:layout_width="90dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.884"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.652"
app:srcCompat="#drawable/ic_add_circle"
tools:ignore="MissingConstraints" />
<TextView
android:id="#+id/MessageLabel"
android:layout_width="293dp"
android:layout_height="23dp"
android:text="Group limit is upto 7 only!!"
android:textColor="#636363"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.454"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.588"
tools:ignore="MissingConstraints" />
<TextView
android:id="#+id/MemberTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Members"
android:textColor="#000000"
android:textSize="30dp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.056"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.447"
tools:ignore="MissingConstraints" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/memberRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
tools:ignore="MissingConstraints"
tools:itemCount="5"
tools:listitem="#layout/fragment_memberlist_card" />
</androidx.constraintlayout.widget.ConstraintLayout>
Error displayed :

Related

Recyclerview items not covering entire screen

I am struggling with a bug for a couple of days. For some reason, my recycler view items don't cover the entire screen.
Here is the code :
feed_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"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="viewModel"
type="com.example.bookally.ui.posts.feed.FeedViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme">
<TextView
style="#style/MainHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/feed"
android:textSize="20sp" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/feeds_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#android:color/white"
android:clipToPadding="false"
android:paddingLeft="16dp"
android:paddingTop="28dp"
android:paddingRight="16dp"
android:paddingBottom="28dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar"
tools:listitem="#layout/item_feed" />
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:src="#drawable/ic_baseline_add_24"
android:onClick="#{() -> viewModel.addPosts()}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:contentDescription="#string/create_post" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
item_feed.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"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="post"
type="com.example.bookally.firebase.PostContent" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:background="#drawable/post_border">
<ImageView
android:id="#+id/author_profile_picture"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:contentDescription="#string/user_image"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:setProfilePhoto="#{post.authorImageUrl}" />
<TextView
android:id="#+id/author_name"
style="#style/MainHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:text="#{post.author}"
android:textSize="18sp"
app:layout_constraintStart_toEndOf="#+id/author_profile_picture"
app:layout_constraintTop_toTopOf="parent"
tools:text="Iqbal Singh" />
<TextView
android:id="#+id/username"
style="#style/MainHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="4dp"
android:text="#{post.username}"
android:textColor="#color/colorGrey"
android:textSize="16sp"
app:layout_constraintStart_toEndOf="#+id/author_profile_picture"
app:layout_constraintTop_toBottomOf="#+id/author_name"
tools:text="\#just_another_boy" />
<TextView
android:id="#+id/post_content"
style="#style/SubHeading"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:gravity="start"
android:text="#{post.content}"
android:textAlignment="viewStart"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/username"
tools:text="Anything random ...." />
<ImageButton
android:id="#+id/like_btn"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:background="#android:color/transparent"
android:contentDescription="#string/likes"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/post_image"
app:likeIcon="#{post.likedBy}" />
<TextView
android:id="#+id/likes_no"
style="#style/MainHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="#+id/like_btn"
app:layout_constraintStart_toEndOf="#+id/like_btn"
app:layout_constraintTop_toTopOf="#+id/like_btn"
app:likesText="#{post.likes}"
tools:text="7 Likes" />
<TextView
android:id="#+id/comments_no"
style="#style/MainHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:textSize="16sp"
app:commentsText="#{post.commentsNumber}"
app:layout_constraintStart_toEndOf="#+id/comment_btn"
app:layout_constraintTop_toTopOf="#+id/comment_btn"
tools:text="0 Comments" />
<ImageButton
android:id="#+id/comment_btn"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:background="#android:color/transparent"
android:contentDescription="#string/comment"
android:src="#drawable/ic_comment"
app:layout_constraintStart_toEndOf="#+id/likes_no"
app:layout_constraintTop_toBottomOf="#+id/post_image" />
<ImageButton
android:id="#+id/save_post_btn"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:background="#android:color/transparent"
android:contentDescription="#string/save_post"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/post_image"
app:saveIcon="#{post.savedBy}" />
<ImageButton
android:id="#+id/add_friend_btn"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:background="#android:color/transparent"
android:contentDescription="#string/add_friend"
android:src="#drawable/ic_add_friend"
app:layout_constraintBottom_toBottomOf="#+id/username"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/author_name" />
<ImageView
android:id="#+id/post_image"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:contentDescription="#string/post_imageview_content_description"
app:layout_constraintBottom_toTopOf="#+id/comments_no"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/post_content"
app:layout_constraintVertical_bias="0.0"
app:loadImagesFromFirebase="#{post.postImageUrl}" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
FeedAdapter
class FeedAdapter(private val onClickListener: ClickListener) : PagingDataAdapter<Post, FeedAdapter.FeedViewHolder>(
DiffCallback
) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FeedViewHolder {
return FeedViewHolder(ItemFeedBinding.inflate(LayoutInflater.from(parent.context)))
}
override fun onBindViewHolder(holder: FeedViewHolder, position: Int) {
val post = getItem(position)
holder.itemView.findViewById<ImageButton>(R.id.like_btn).setOnClickListener { if (post != null) onClickListener.onLikeClicked(post) }
holder.itemView.findViewById<ImageButton>(R.id.comment_btn).setOnClickListener { if (post != null) onClickListener.onCommentClicked(post) }
holder.itemView.findViewById<ImageButton>(R.id.save_post_btn).setOnClickListener { if (post != null) onClickListener.onSavePostClicked(post) }
holder.itemView.findViewById<ImageButton>(R.id.add_friend_btn).setOnClickListener { if (post != null) onClickListener.onAddFriendClicked(post) }
if (post != null) holder.bind(post.postContent)
}
class FeedViewHolder(private val binding : ItemFeedBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(feed: PostContent) {
binding.post = feed
binding.executePendingBindings()
}
}
In the design tab, everything looks fine :
However, the problem arises in real devices :
However, if I add a view like this, the items cover the entire screen :
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/like_btn" />
Any help would be really appreciated. Thanks in advance !!
I believe the problem is here:
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FeedViewHolder {
return FeedViewHolder(ItemFeedBinding.inflate(LayoutInflater.from(parent.context)))
}
Because you are calling the overload of inflate() that does not specify a parent view, your item view's layout params are being ignored. Change it to this instead:
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FeedViewHolder {
return FeedViewHolder(ItemFeedBinding.inflate(LayoutInflater.from(parent.context), parent, false))
}
you problem is
android:layout_height="wrap_content"
<TextView
android:id="#+id/post_content"
style="#style/SubHeading"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:gravity="start"
android:text="#{post.content}"
android:textAlignment="viewStart"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/username"
tools:text="Anything random ...." />
you must set fixedHeight or use maxLines and set width to match_parent
also remove this line android:textAlignment="viewStart"

getInfoContents not show my custom marker's view (ConstraintLayout)

android studio 3.6
I need to show custom view when click on map's marker:
implementation 'com.google.android.gms:play-services-maps:17.0.0'
snippet to show marker info window
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
mMap.setInfoWindowAdapter(object : GoogleMap.InfoWindowAdapter {
override fun getInfoWindow(marker: Marker): View? {
return null
}
override fun getInfoContents(marker: Marker): View? {
val markerLatLng = marker.position
val selectGazStattion =
gazStationsList.first { it.latitude == markerLatLng.latitude && it.longitude == markerLatLng.longitude }
val customView = layoutInflater.inflate(
R.layout.map_marker_info_content_layout, null
)
val textView : TextView = customView.findViewById(R.id.addressValueTextView)
textView.setText(selectGazStattion.address)
return customView
}
})
here map_marker_info_content_layout.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="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/titleContainerLayout"
android:layout_width="0dp"
android:layout_height="#dimen/min_height"
android:layout_marginStart="#dimen/half_default_margin"
android:layout_marginTop="#dimen/default_margin"
android:layout_marginEnd="#dimen/half_default_margin"
android:background="#drawable/bottom_border_bg"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/titleTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/half_default_margin"
android:gravity="center|start"
android:text="Title"
android:textColor="#android:color/black"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/stateTtextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/open"
android:textColor="#android:color/holo_green_light"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/titleTextView"
app:layout_constraintStart_toStartOf="#+id/titleTextView"
app:layout_constraintTop_toBottomOf="#+id/titleTextView" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/containerAgentInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/half_default_margin"
android:background="#drawable/bottom_border_bg"
app:layout_constraintEnd_toEndOf="#+id/titleContainerLayout"
app:layout_constraintStart_toStartOf="#+id/titleContainerLayout"
app:layout_constraintTop_toBottomOf="#+id/titleContainerLayout">
<TextView
android:id="#+id/addressLabelTextView"
style="#style/mapMarkerInfoItemLabelTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/half_default_margin"
android:layout_marginEnd="#dimen/half_default_margin"
android:text="#string/address_colon"
app:layout_constraintEnd_toStartOf="#+id/addressValueTextView"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/addressValueTextView"
style="#style/mapMarkerInfoItemLabelTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="end"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/addressLabelTextView"
app:layout_constraintTop_toTopOf="#+id/addressLabelTextView" />
<TextView
android:id="#+id/workingHoursLabelTextView"
style="#style/mapMarkerInfoItemLabelTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/half_default_margin"
android:text="#string/working_hours_colon"
app:layout_constraintEnd_toEndOf="#+id/addressLabelTextView"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/addressLabelTextView"
app:layout_constraintTop_toBottomOf="#+id/addressLabelTextView" />
<TextView
android:id="#+id/workingHoursValueTextView"
style="#style/mapMarkerInfoItemLabelTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="end"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/addressValueTextView"
app:layout_constraintTop_toTopOf="#+id/workingHoursLabelTextView" />
<TextView
android:id="#+id/phoneLabelTextView"
style="#style/mapMarkerInfoItemLabelTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/half_default_margin"
android:text="#string/phone_colon"
app:layout_constraintEnd_toEndOf="#+id/addressLabelTextView"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/workingHoursLabelTextView"
app:layout_constraintTop_toBottomOf="#+id/workingHoursLabelTextView" />
<TextView
android:id="#+id/phoneValueTextView"
style="#style/mapMarkerInfoItemLabelTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="end"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/addressValueTextView"
app:layout_constraintTop_toTopOf="#+id/phoneLabelTextView" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/containerServices"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/half_default_margin"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/titleContainerLayout"
app:layout_constraintStart_toStartOf="#+id/titleContainerLayout"
app:layout_constraintTop_toBottomOf="#+id/containerAgentInfo">
<TextView
android:id="#+id/servicesTextView"
style="#style/mapMarkerInfoItemLabelTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/half_default_margin"
android:layout_marginEnd="#dimen/half_default_margin"
android:text="#string/services_colon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.yarolegovich.discretescrollview.DiscreteScrollView
android:id="#+id/agetServiceDiscreteScrollView"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:dsv_orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/servicesTextView" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
But when I click on marker I get this:
Why not show my custom view?
P.S. If I use LinearLayout then success show info window. But with androidx.constraintlayout.widget.ConstraintLayout not work

All RecyclerView items are not visible when using RecyclerView in ConstraintLayout

I am using ConstraintLayout as a parent and put recyclerview in it to populate the list. Suppose I have to give item count 5 to populate the list and run the code then the list is showing perfectly but the last item of the recyclerview is showing half and not fully visible, and scroll stops at there. I found a solution for this is if am giving height match_parent to the recyclerview then it works fine but then all other view is hidden behind the recyclerview.
If I use another parent view like LinearLayout or RelativeLayout, then recyclerview with height wrap_content works fine and all the list item are fully visible.
I have tried by 2 ways that work for me but I found that wrong programming practice
I give height match_parent to recyclerview and give top_margin to the recylerview so all the other UI item show.
I give padding_bottom to the recyclerview until all the list item position visible
My XML file "activity_per_day_sale.xml" is below.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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/black">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:popupTheme="#style/AppTheme.PopupOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/btn_back"
android:padding="5dp"
android:onClick="OnClickPerDaySale"
android:background="?attr/selectableItemBackground"
android:src="#drawable/icon_back_white"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Signup"
android:layout_centerInParent="true"
android:id="#+id/home_title_text"
android:textColor="#color/black"
android:visibility="gone"
android:fontFamily="#font/seguisb"
android:textSize="18sp"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SKIP"
android:padding="10dp"
android:layout_centerVertical="true"
android:visibility="gone"
android:id="#+id/skip"
android:textColor="#color/black"
android:fontFamily="#font/seguisb"
android:textSize="18sp"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:layout_marginTop="10dp"
android:text="Per Day Sale Details"
android:textColor="#color/yellow_app_logo_color"
android:fontFamily="#font/segoeuib"
app:layout_constraintTop_toBottomOf="#+id/toolbar"
app:layout_constraintStart_toStartOf="parent"
android:id="#+id/TV_signupScreenText"
android:layout_marginLeft="45dp"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rv_perday_sale"
android:layout_marginTop="10dp"
android:layout_marginHorizontal="10dp"
app:layout_constraintTop_toBottomOf="#+id/TV_signupScreenText"/>
</android.support.constraint.ConstraintLayout>
Activity class is "PerDaySaleActivity.kt"
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.StaggeredGridLayoutManager
import android.view.View
import com.nq.NQManager.R
import com.nq.NQManager.utils.BaseActivity
import kotlinx.android.synthetic.main.activity_per_day_sale.*
class PerDaySaleActivity:BaseActivity(){
var adapterPerdaySale : AdapterPerdaySale? = null
companion object {
fun start(context: Context) {
val starter = Intent(context, PerDaySaleActivity::class.java)
context.startActivity(starter)
}
}
override fun getID(): Int {
return R.layout.activity_per_day_sale
}
override fun iniView(savedInstanceState: Bundle?) {
initViews()
}
fun OnClickPerDaySale(v: View){
when(v){
btn_back->{
finish()
}
}
}
fun initViews() {
adapterPerdaySale = AdapterPerdaySale( this)
rv_perday_sale.layoutManager = StaggeredGridLayoutManager(1, 1)
rv_perday_sale.adapter = adapterPerdaySale
}
private fun setUpRecyclerView() {
runOnUiThread { adapterPerdaySale!!.notifyDataSetChanged() }
}
My Adapter class "AdapterPerdaySale.kt"
mport android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.nq.NQManager.R
import kotlinx.android.synthetic.main.adapter_perday_sale.view.*
class AdapterPerdaySale(context: Context):
RecyclerView.Adapter<AdapterPerdaySale.MyViewHOlder>() {
private var ctx:Context?=context
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): MyViewHOlder {
return MyViewHOlder(LayoutInflater.from(ctx).inflate(R.layout.adapter_perday_sale, p0, false))
}
override fun getItemCount(): Int {
return 5
}
override fun onBindViewHolder(holder: MyViewHOlder, position: Int) {
if (position==1){
holder.tv_date.text="26 June, 2019"
}else if(position==2){
holder.tv_date.text="27 June, 2019"
}
}
inner class MyViewHOlder(view: View) : RecyclerView.ViewHolder(view) {
val tv_date=view.tv_date
}
}
My Adapter xml file "adapter_perday_sale.xml"
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="wrap_content"
android:paddingVertical="5dp"
android:background="#color/black">
<TextView
android:id="#+id/tv_date"
android:layout_below="#+id/txt_today"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:fontFamily="#font/segoeuib"
android:text="25 June, 2019"
android:textSize="23sp"
android:layout_marginEnd="8dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginRight="8dp" android:layout_marginStart="8dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="8dp" android:layout_marginTop="8dp"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="#+id/tv_date">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:layout_marginTop="5dp"
android:text="Orders"
android:layout_centerHorizontal="true"
android:textColor="#color/white"
android:fontFamily="#font/segoeuib"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="50sp"
android:layout_marginTop="0dp"
android:text="50"
android:layout_centerHorizontal="true"
android:textColor="#color/order_history_txt_color"
android:fontFamily="#font/segoeui"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:layout_marginTop="5dp"
android:text="Revenue"
android:layout_centerHorizontal="true"
android:textColor="#color/white"
android:fontFamily="#font/segoeuib"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="50sp"
android:layout_marginTop="0dp"
android:text="£550"
android:layout_centerHorizontal="true"
android:textColor="#color/order_history_txt_color"
android:fontFamily="#font/segoeui"/>
</LinearLayout>
</LinearLayout>
<View android:layout_width="match_parent"
android:layout_height="1.5dp"
android:background="#color/gray"
android:id="#+id/view_1"
app:layout_constraintTop_toBottomOf="#+id/linearLayout1"
android:layout_marginLeft="8dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"/>
</android.support.constraint.ConstraintLayout>
Add this app:layout_constraintBottom_toBottomOf="parent" property to your recyclerview
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="#style/AppTheme.PopupOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<ImageView
android:id="#+id/btn_back"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="?attr/selectableItemBackground"
android:onClick="OnClickPerDaySale"
android:padding="5dp"
android:src="#drawable/ic_background" />
<TextView
android:id="#+id/home_title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Signup"
android:textColor="#000"
android:textSize="18sp"
android:visibility="gone" />
<TextView
android:id="#+id/skip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="10dp"
android:text="SKIP"
android:textColor="#000"
android:textSize="18sp"
android:visibility="gone" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
<TextView
android:id="#+id/TV_signupScreenText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_marginTop="10dp"
android:text="Per Day Sale Details"
android:textColor="#AD4E4E"
android:textSize="25sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_perday_sale"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#+id/TV_signupScreenText" />
</androidx.constraintlayout.widget.ConstraintLayout>

Android gridview in fragment can't scrolling

I have one page called products. When page is loaded it shows productsfragment. This fragment has one RecyclerView which doesn't have any problem. On selecting a product a new fragment opens up and shows the list of product prices fragment. This fragment has one RecyclerView and the scrolling here doesn't works.
I tried gridview and cardview but they too are not scrolling. I tried gridview in scroll view or nested scroll view, they are also not scrolling.
here is my fragment with RecyclerView which is not scrolling
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/sorderfragment_step1_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Activities.OrderSelect.Fragments.ProductSingleOrder.SOrderFragment_Step1">
<android.support.v7.widget.RecyclerView
android:id="#+id/gvProductPrices"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
and its my RecyclerView item view
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="200dp"
android:layout_height="200dp"
android:gravity="center"
android:maxHeight="200dp"
android:minHeight="200dp"
android:background="#layout/border2"
android:padding="0dp"
android:orientation="vertical">
<TextView
android:id="#+id/txtPriceName"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:text="Kucuk Boy Whopper"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/constraintLayout4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout4"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="0dp"
android:background="#000000"
app:layout_constraintBottom_toTopOf="#+id/txtPrice"
app:layout_constraintEnd_toEndOf="parent">
</android.support.constraint.ConstraintLayout>
<TextView
android:id="#+id/txtPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:gravity="center"
android:text="14.99"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</LinearLayout>
and my adapter
class PriceAdapter(val priceList : List<ProductPrice>,
val context: Context) : RecyclerView.Adapter<ViewHolder>() {
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(context).inflate(R.layout.gv_product_prices, p0, false))
}
override fun getItemCount(): Int {
return priceList.size
}
override fun onBindViewHolder(p0: ViewHolder, p1: Int) {
val price = priceList[p1]
p0.txtPriceName.text = price.getDescription()
p0.txtPriceName.isAllCaps = true
p0.txtPrice.text = BaseHelper.getNumericStr(price.getPrice())
}
}
class ViewHolder (view: View) : RecyclerView.ViewHolder(view) {
val txtPriceName = view.txtPriceName!!
val txtPrice = view.txtPrice!!
}
and my fragment code
class SOrderFragment_Step1 : Fragment() {
private var _priceRepository = ProductPriceRepository(OrderRepository.orderSelect!!)
private var priceAdapter: PriceAdapter? = null
private var prices: List<ProductPrice>? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_sorder_step1, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
configurePrices()
}
private fun configurePrices() {
prices = _priceRepository.getPriceByProductId(OrderRepository.currentProduct!!.getId())
gvProductPrices.layoutManager = GridLayoutManager(OrderRepository.orderSelect!!, 2)
gvProductPrices.adapter = PriceAdapter(prices!!, this, OrderRepository.orderSelect!!)
}
fun priceSelect(price: ProductPrice) {
Toast.makeText(OrderRepository.orderSelect!!, price.getDescription(), Toast.LENGTH_LONG).show()
}
}
and also fragment change like this
val manager = this.fragmentManager!!.beginTransaction()
manager.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
manager.replace(R.id.fragmentProductSteps, SOrderFragment_Step1(), "detailFragment").commit()
and fragment base activity xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:id="#+id/order_select_layout"
tools:context=".OrderSelect">
<GridView
android:id="#+id/gvProductGroups"
android:layout_width="165dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
android:scrollbars="none"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="0dp"
android:layout_height="225dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="7">
<include
layout="#layout/activity_advertise_partition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/orderProductLayout"
android:layout_width="0dp"
android:layout_height="83dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="#layout/gv_order_products_border"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/btnCancelCurrentOrder2"
app:layout_constraintStart_toEndOf="#+id/gvProductGroups">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:id="#+id/paymentView"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="1">
<TextView
android:id="#+id/txtTotalL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TOPLAM :"
android:textColor="#bc3030"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/txtPriceL"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="-1dp"
android:layout_weight="1"
android:gravity="left|center"
android:text="₺ 0.00"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imgOrderButton"
app:layout_constraintStart_toEndOf="#+id/txtTotalL"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<Button
android:id="#+id/imgOrderButton"
android:layout_width="175dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:background="#15912e"
android:padding="15sp"
android:text="Sepeti Goster"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
<fragment
android:id="#+id/fragmentProductSteps"
android:name="com.example.alknakralar.kios.Helpers.BlankFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="#+id/orderProductLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/gvProductGroups"
app:layout_constraintTop_toBottomOf="#+id/linearLayout" />
<Button
android:id="#+id/btnCancelCurrentOrder2"
android:layout_width="125dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:background="#ff0000"
android:text="SEPETI BOSALT"
android:textColor="#FFFFFF"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imgBackFromProducts"
app:layout_constraintTop_toBottomOf="#+id/fragmentProductSteps" />
<ImageView
android:id="#+id/imgBackFromProducts"
android:layout_width="70dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragmentProductSteps"
app:srcCompat="#drawable/back" />
</android.support.constraint.ConstraintLayout>
How can i fix this issue ?
Sugession: Why are you using grid view and setting adapter to it where you have another approach and commonly used approach.
Which is to use recycler view and set its layout manager as GridLayout manager
Below single line will make your job done
recyclerView.setLayoutManager(new GridLayoutManager(this, numberOfColumns));

RecyclerView cells deform when keyboard opened

I am implementing a chat inside my app, and the recycler view behave in wired way when the keyboard opened, the cards expands by itself
I tried to disable the recycling ,change the way I build the layout but nothing works,I need to understand why this happened and how to fix it.
The XML layout for the view
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical"
tools:context="io.thed.cuju.ChatDetailsFragment">
<LinearLayout
android:id="#+id/linearLayout22"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/chat_image"
android:layout_width="32dp"
android:layout_height="32dp"
tools:src="#drawable/avatar" />
<TextView
android:id="#+id/name_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:textSize="16sp"
tools:text="Bradley Anderson" />
</LinearLayout>
<include
android:id="#+id/say_hi"
layout="#layout/say_hi_chat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<android.support.constraint.ConstraintLayout
android:id="#+id/chat_list_and_input_section"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/chat_details_recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
app:layout_constraintBottom_toTopOf="#+id/linearLayout5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/space2"
app:reverseLayout="true"
tools:listitem="#layout/recived_chat_box_item" />
<TextView
android:id="#+id/space2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/Gray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ProgressBar
android:id="#+id/progressBar12"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="#+id/linearLayout5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<EditText
android:id="#+id/to_be_sent_chat"
style="#style/cujuEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:ems="10"
android:hint="Type a message"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/chat_extra"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/send_chat"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/to_be_sent_chat"
app:layout_constraintTop_toTopOf="#+id/to_be_sent_chat" />
<ImageView
android:id="#+id/chat_extra"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:src="#drawable/add_media_circle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
The Adapter
package io.thed.cuju.adapters
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.support.v4.content.ContextCompat
import android.support.v7.widget.RecyclerView
import android.text.format.DateUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.google.gson.Gson
import com.pddstudio.preferences.encrypted.EncryptedPreferences
import com.squareup.picasso.Picasso
import io.thed.cuju.R
import io.thed.cuju.beans.MessageBean
import io.thed.cuju.beans.UserBean
import io.thed.cuju.constants.*
import io.thed.cuju.customsViews.ZoomImageFragment
import java.text.SimpleDateFormat
import java.util.*
class ChatDetailsAdapter// Provide a suitable constructor (depends on the kind of dataset)
(private val chatList: List<MessageBean>, internal var context: Context) : RecyclerView.Adapter<ChatDetailsAdapter.ViewHolder>() {
internal var token: String? = null
internal var user: UserBean? = null
val SENT_CHAT = 1
val RECIVED_CHAT = 2
override fun getItemViewType(position: Int): Int {
val current: MessageBean = chatList[position]
val encryptedPreferences = EncryptedPreferences.Builder(context).withEncryptionPassword(PASSWORD).build()
var token: String = encryptedPreferences.getString(USER_PREF_TOKEN_KEY, NO_TOKEN)
tokenForImage = "?x-access-token=" + token
user = Gson().fromJson(encryptedPreferences!!.getString(USER_PREF_KEY, ""), UserBean::class.java)
if (user!!._id != current.from) {
return RECIVED_CHAT
} else {
return SENT_CHAT
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChatDetailsAdapter.ViewHolder {
val v: View?
if (viewType == SENT_CHAT) {
v = LayoutInflater.from(parent.context).inflate(R.layout.send_chat_box_item, parent, false)
} else {
v = LayoutInflater.from(parent.context).inflate(R.layout.recived_chat_box_item, parent, false)
}
return ViewHolder(v)
}
// set the view's size, margins, paddings and layout parameters
lateinit var tokenForImage: String
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val current = chatList[position]
holder.setIsRecyclable(false)
if (current.data.text != null) {
holder.chat_text.text = current.data.text
}
if (current.data.type == "picture") {
val url = BASE_URL + current.data.media!!.thumbnail + tokenForImage
Picasso.with(context).load(Uri.parse(url)).fit().placeholder(context.resources.getDrawable(R.drawable.placeholder)).into(holder.chat_image)
holder.chat_image.visibility = View.VISIBLE
holder.chat_play.visibility = View.GONE
holder.chat_image.setOnClickListener {
ZoomImageFragment.newInstance(url).show((context as Activity).fragmentManager, "")
}
} else if (current.data.type == "video") {
val url = BASE_URL + current.data.media!!.thumbnail + tokenForImage
Picasso.with(context).load(Uri.parse(url)).fit().placeholder(context.resources.getDrawable(R.drawable.placeholder)).into(holder.chat_image)
holder.chat_image.visibility = View.VISIBLE
holder.chat_play.visibility = View.VISIBLE
holder.chat_image.setOnClickListener {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(BASE_URL + current.data.media.link + tokenForImage))
ContextCompat.startActivity(context, intent, null)
}
} else {
holder.chat_image.visibility = View.GONE
holder.chat_play.visibility = View.GONE
}
val formatter = SimpleDateFormat(DATE_FORMAT)
formatter.timeZone = TimeZone.getTimeZone("GMT")
try {
val dateToBeParsed = DateUtils.getRelativeTimeSpanString(formatter.parse(current.created_at).time, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS)
holder.chat_time.text = dateToBeParsed
} catch (e: Exception) {
println(e.message)
holder.chat_time.text = current.created_at
}
if (holder.itemViewType == SENT_CHAT) {
if (current.failed) {
holder.chat_status!!.setImageResource(R.drawable.message_seen)
} else if (current.seen) {
holder.chat_status!!.setImageResource(R.drawable.message_seen)
} else if (current.received) {
holder.chat_status!!.setImageResource(R.drawable.message_recived_not_seen)
} else if (current.sent) {
holder.chat_status!!.setImageResource(R.drawable.message_sent_to_server)
}
}
}
override fun getItemCount(): Int {
return chatList.size
}
class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
val chat_image: ImageView = v.findViewById(R.id.chat_image)
val chat_play: ImageView = v.findViewById(R.id.chat_play)
val chat_text: TextView = v.findViewById(R.id.chat_text)
val chat_time: TextView = v.findViewById(R.id.chat_time)
val chat_status: ImageView? = v.findViewById(R.id.chat_status)
}
}
reviced_chat_box_item.xml (sorry for the typo)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">
<android.support.v7.widget.CardView
android:id="#+id/cardView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="12dp"
app:cardBackgroundColor="#color/recivedChat"
app:cardCornerRadius="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<ImageView
android:id="#+id/chat_image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/chat_text"
tools:srcCompat="#drawable/content_image" />
<ImageView
android:id="#+id/chat_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="#+id/chat_image"
app:layout_constraintEnd_toEndOf="#+id/chat_image"
app:layout_constraintStart_toStartOf="#+id/chat_image"
app:layout_constraintTop_toTopOf="#+id/chat_image"
app:srcCompat="#drawable/play" />
<TextView
android:id="#+id/chat_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:layout_marginEnd="2dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="2dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="Hello buddy, gonna go for a training today?"
android:textColor="#color/chat_color"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<TextView
android:id="#+id/chat_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_marginTop="4dp"
android:text="12 mins ago"
android:textColor="#color/time_ago"
android:textSize="13sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardView2" />
</android.support.constraint.ConstraintLayout>
send_chat_box_item.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">
<android.support.v7.widget.CardView
android:id="#+id/cardView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:layout_marginStart="8dp"
app:cardCornerRadius="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<ImageView
android:id="#+id/chat_image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/chat_text"
tools:srcCompat="#drawable/content_image" />
<ImageView
android:id="#+id/chat_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="#+id/chat_image"
app:layout_constraintEnd_toEndOf="#+id/chat_image"
app:layout_constraintStart_toStartOf="#+id/chat_image"
app:layout_constraintTop_toTopOf="#+id/chat_image"
app:srcCompat="#drawable/play" />
<TextView
android:id="#+id/chat_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="16dp"
android:layout_marginStart="2dp"
android:layout_marginTop="8dp"
android:text="Hello buddy, gonna go for a training today?"
android:textColor="#color/chat_color"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<TextView
android:id="#+id/chat_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
android:layout_marginTop="4dp"
android:text="12 mins ago"
android:textColor="#color/time_ago"
android:textSize="13sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardView2" />
<ImageView
android:id="#+id/chat_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="#+id/chat_time"
app:layout_constraintEnd_toStartOf="#+id/chat_time"
app:layout_constraintTop_toTopOf="#+id/chat_time"
app:srcCompat="#drawable/message_seen" />
</android.support.constraint.ConstraintLayout>

Categories

Resources