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"
Related
I have the following XML
<?xml version="1.0" encoding="utf-8"?>
<layout>
<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/fragment_inspection_details_root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="#dimen/size_0dp"
android:layout_height="#dimen/size_0dp"
app:layout_constraintBottom_toTopOf="#+id/fragment_inspection_details_buttons_container"
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">
<TextView
android:id="#+id/fragment_inspection_details_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
android:text="#string/details"
android:textAllCaps="true"
android:textColor="#color/gold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:layout_width="#dimen/size_0dp"
android:layout_height="1dp"
android:layout_margin="#dimen/size_16dp"
android:background="#color/lightGray"
app:layout_constraintBottom_toBottomOf="#+id/fragment_inspection_details_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/fragment_inspection_details_title"
app:layout_constraintTop_toTopOf="#+id/fragment_inspection_details_title" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/fragment_inspection_details_status_til"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_title">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/fragment_inspection_details_status_tie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:hint="#string/status" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/fragment_inspection_details_start_time_til"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_status_til">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/fragment_inspection_details_start_time_tie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:hint="#string/start_time" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/fragment_inspection_details_end_time_til"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_start_time_til">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/fragment_inspection_details_end_time_tie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:hint="#string/end_time" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/fragment_inspection_details_desc_time_til"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_end_time_til">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/fragment_inspection_details_desc_time_tie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:hint="#string/description" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="#+id/fragment_inspection_details_handling_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
android:text="#string/handling"
android:textAllCaps="true"
android:textColor="#color/gold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_desc_time_til" />
<View
android:layout_width="#dimen/size_0dp"
android:layout_height="1dp"
android:layout_margin="#dimen/size_16dp"
android:background="#color/lightGray"
app:layout_constraintBottom_toBottomOf="#+id/fragment_inspection_details_handling_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/fragment_inspection_details_handling_title"
app:layout_constraintTop_toTopOf="#+id/fragment_inspection_details_handling_title" />
<TextView
android:id="#+id/fragment_inspection_details_outcome_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
android:text="#string/outcome"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_handling_title" />
<Spinner
android:id="#+id/fragment_inspection_details_outcome_spinner"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/size_8dp"
android:layout_marginEnd="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_outcome_title" />
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/size_16dp"
android:layout_marginEnd="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_outcome_spinner">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/fragment_inspection_details_outcome_report_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Outcome report" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<LinearLayout
android:id="#+id/fragment_inspection_details_buttons_container"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<androidx.appcompat.widget.AppCompatButton
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
android:layout_weight="1"
android:background="#drawable/white_background_gray_rounded_border"
android:text="#string/save"
android:textAllCaps="false" />
<androidx.appcompat.widget.AppCompatButton
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
android:layout_weight="1"
android:background="#drawable/white_background_gray_rounded_border"
android:text="#string/handle"
android:textAllCaps="false" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
and the following code -
class InspectionDetailsFragment : Fragment() {
companion object {
fun newInstance(inspection: Inspection): InspectionDetailsFragment {
val inspectionDetailsFragment = InspectionDetailsFragment()
val bundle = Bundle()
bundle.putParcelable(Constants.INSPECTION, inspection)
inspectionDetailsFragment.arguments = bundle
return inspectionDetailsFragment
}
}
...
...
}
//Inside another Fragment
changeFragment(
parentFragmentManager, R.id.fragment_inspection_details_root,
InspectionDetailsFragment.newInstance(inspection), true
)
// Change fragment extension function to handle navigation easily
#SuppressLint("PrivateResource")
fun changeFragment(fragmentManager: FragmentManager?, #IdRes containerId: Int, fragment: Fragment?, addToBackStack: Boolean = false) {
if (fragmentManager == null) return
val fragmentTransaction = fragmentManager.beginTransaction()
if (addToBackStack) fragmentTransaction.addToBackStack(null)
/*fragmentTransaction.setCustomAnimations(
R.anim.abc_fade_in,
R.anim.abc_shrink_fade_out_from_bottom,
R.anim.abc_grow_fade_in_from_bottom,
R.anim.abc_popup_exit
)*/
fragment?.let {
fragmentTransaction
.replace(containerId, it, it::class.java.simpleName)
.commit()
}
}
For some reason when trying to navigate to the InspectionDetailsFragment the app crashes with the No view found for id 0x7f0900df (com.supercom.myapplication:id/fragment_inspection_details_root) for fragment InspectionDetailsFragment I really have no idea what's wrong, I tried to look up but it seems like I am doing everything correct.
The InspectionDetailsFragment used to have a container fragment for it but I deleted it, maybe that is related to the issue I am getting?
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
I have a view that uses constraint layout. The view has an edit text and expects the soft keyboard input to show up. There are two buttons pinned to the bottom of the screen(Previous and Next). When the soft keyboard opens up, the two buttons hide behind the keyboard. However, I want the layout to resize so that the buttons are above the soft keyboard and not behind it.
I have the following in my manifest.
<activity
android:name=".activity.SomeActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
</activity>
I have looked at various other posts and tried a few different things like, adjustPan. I have set
android:fitsSystemWindows="true"
But both of them did not work.
My Constraint layout looks like this.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorLibWhite"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context=".ui.main.question.QuestionFragment">
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dp"
android:layout_height="8dp"
android:layout_marginTop="4dp"
android:background="#color/colorLibWhite"
android:indeterminate="false"
android:progressDrawable="#drawable/progress_bar_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="#+id/sectionHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="#color/colorLibLighterGray"
android:ellipsize="end"
android:maxLines="2"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp"
android:text="new section"
android:textColor="#color/colorLibGray"
android:textSize="12sp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="#+id/questionLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/progressBar"/>
<TextView
android:id="#+id/questionLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:text="#string/placeholder"
android:textAlignment="center"
app:layout_constraintBottom_toTopOf="#+id/inputContainerCL"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/sectionHeader"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/inputContainerCL"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="#+id/prevNextContainer"
app:layout_constraintTop_toBottomOf="#+id/questionLabel">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/inputContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="#+id/hintText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:text="Hint text goes here"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/inputContainer"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/prevNextContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="#+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="16dp"
android:background="#drawable/primary_button"
android:text="#string/question_previous"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<Button
android:id="#+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="16dp"
android:background="#drawable/primary_button"
android:text="#string/question_next"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
EditText is added programatically.
var editText = CustomEditText(context)
editText.apply {
id = View.generateViewId()
layoutParams = ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.WRAP_CONTENT)
setSingleLine(true)
imeOptions = EditorInfo.IME_ACTION_DONE
val questionType = question.validation?.type
if (questionType == Validation.Type.INTEGER) {
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_SIGNED
} else if (questionType == Validation.Type.NUMBER) {
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_SIGNED or InputType.TYPE_NUMBER_FLAG_DECIMAL
} else if (questionType == Validation.Type.MRN) {
inputType = InputType.TYPE_CLASS_NUMBER
filters = arrayOf(InputFilter.LengthFilter(9))
} else if (questionType == Validation.Type.ZIP_CODE) {
inputType = InputType.TYPE_CLASS_PHONE
filters = arrayOf(InputFilter.LengthFilter(10))
} else if (questionType == Validation.Type.PHONE) {
inputType = InputType.TYPE_CLASS_NUMBER
editText.setSelection(editText.text?.length!!)
editText.addTextChangedListener(PhoneFormatterTextWatcher(editText))
}
tag = TAG_FOCUS_FIRST
}
editText.setText(question.value ?: "")
if (question.validation?.type == Validation.Type.ZIP_CODE) {
editText.addTextChangedListener(ZipCodeTextWatcher(editText, question, updateCallback))
} else {
editText.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {
//
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
//
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
question.value = if (s != null && s.isNotBlank()) s.toString() else null
updateCallback()
}
}
)
}
editText.setOnEditorActionListener() { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
doneCallback()
true
} else {
false
}
}
return editText
Here is the code that adds this view to input container
inputContainer.addView(editText)
Where is your EditText view?.I think you must learn about Constraint Layout. how ever you can try this xml layout code..
Add your styles for views.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context=".ui.main.question.QuestionFragment">
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="411dp"
android:layout_height="7dp"
android:indeterminate="false"
android:progress="40"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/sectionHeader"
android:layout_width="99dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:maxLines="2"
android:paddingStart="16dp"
android:visibility="gone"
android:paddingTop="8dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp"
android:text="new section"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/progressBar" />
<TextView
android:id="#+id/questionLabel"
android:layout_width="379dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="questionLabel"
android:layout_marginRight="8dp"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/sectionHeader" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/inputContainerCL"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toTopOf="#+id/prevNextContainer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/questionLabel">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/inputContainer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toTopOf="#+id/hintText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" >
<EditText
android:id="#+id/editText2"
android:layout_width="0dp"
android:layout_height="0dp"
android:ems="10"
android:gravity="top"
android:text="text"
android:inputType="textMultiLine"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="#+id/hintText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:text="Hint text goes here"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/prevNextContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="#+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginBottom="8dp"
android:text="question_previous"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="16dp"
android:text="question_next"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
this is the preview
I have a recyclerview that inflates data fetched from json.
The issue I am facing are design issues - sometimes the text is aligned correctly and the image is shown and sometimes the text is too long, causing what I think is for the image not to be shown.
here is my 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.support.constraint.ConstraintLayout
android:layout_width="395dp"
android:layout_height="170dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:background="#335634"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/heroImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:src="#mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/heroTitle"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:autoSizeMaxTextSize="25dp"
android:autoSizeMinTextSize="15dp"
android:text="Hero Title"
android:textSize="25dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/heroDescription"
android:layout_width="200dp"
android:breakStrategy="simple"
android:layout_height="wrap_content"
android:layout_marginStart="36dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:autoSizeMaxTextSize="25dp"
android:autoSizeMinTextSize="15dp"
android:text="TextView"
android:textAlignment="center"
android:textSize="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/heroImage"
app:layout_constraintTop_toBottomOf="#+id/heroTitle" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
and here is my adapter:
public class HeroesAdapter extends RecyclerView.Adapter<HeroesAdapter.HeroesViewHolder> {
private List<Hero> heroList;
public HeroesAdapter(List<Hero> heroList) {
this.heroList = heroList;
}
#NonNull
#Override
public HeroesViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View rowView = LayoutInflater.from(parent.getContext()).inflate(R.layout.hero_cell, parent, false);
return new HeroesViewHolder(rowView);
}
#Override
public void onBindViewHolder(#NonNull HeroesViewHolder holder, int position) {
Hero currentHero = heroList.get(position);
String str = String.join(",", currentHero.abilities);
holder.heroTitle.setText(currentHero.title);
holder.heroAbilties.setText(str);
Picasso.get().load(currentHero.image).resize(500,500).into(holder.heroesImage);
}
#Override
public int getItemCount() {
return heroList.size();
}
public static class HeroesViewHolder extends RecyclerView.ViewHolder {
ImageView heroesImage;
TextView heroTitle;
TextView heroAbilties;
public HeroesViewHolder(#NonNull View itemView) {
super(itemView);
heroesImage = itemView.findViewById(R.id.heroImage);
heroTitle = itemView.findViewById(R.id.heroTitle);
heroAbilties = itemView.findViewById(R.id.heroDescription);
}
}
}
This is the result I am getting and this is the wanted result.
the issues I am facing are:
making each row have a clean design and act the same for all.
images are sometimes shown, sometimes not.
bottom view is "half in screen" and half out of screen.
By using LinearLayout you can design your hero_cell that will give you the desirable output. as I do it for now.
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:padding="10dp"
android:background="#335634"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/heroImage"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:src="#drawable/logo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:background="#335634"
android:layout_marginLeft="20dp"
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/heroTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoSizeMaxTextSize="25dp"
android:autoSizeMinTextSize="15dp"
android:text="Hero Title"
android:textSize="25dp"
android:textStyle="bold"
/>
<TextView
android:id="#+id/heroDescription"
android:layout_width="match_parent"
android:breakStrategy="simple"
android:layout_height="wrap_content"
android:autoSizeMaxTextSize="25dp"
android:autoSizeMinTextSize="15dp"
android:text="TextView"
android:textSize="18dp" />
</LinearLayout>
According to your expectation, you should use card-view and I've updated the layout. Please check
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_margin="10dp"
app:cardCornerRadius="10dp"
android:elevation="10dp"
android:layout_height="wrap_content">
<android.support.constraint.ConstraintLayout
android:layout_width="395dp"
android:layout_height="170dp"
android:background="#fff"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/heroImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:src="#mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/heroTitle"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="16dp"
android:autoSizeMaxTextSize="25dp"
android:autoSizeMinTextSize="15dp"
android:text="Hero Title"
android:textColor="#000"
android:textSize="25dp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/heroDescription"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/heroImage"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/heroDescription"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:autoSizeMaxTextSize="25dp"
android:autoSizeMinTextSize="15dp"
android:breakStrategy="simple"
android:text="TextView"
android:textColor="#444"
android:textSize="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/heroImage"
app:layout_constraintTop_toBottomOf="#+id/heroTitle" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
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));