Stateflow value not getting being observed in data binding - android

I have a stateflow that is giving me the value of a mutable state flow from ViewModel, what I am trying to do is, I want to show hide a webview based on a button click. When the value is true I want to show the web view and when I want to hide it I change its value to false. The values are being updated correctly but not reflecting inside data binding.
this is my viewmodel
class ArticleDetailsViewModel : ViewModel() {
private val _isWebViewShowing = MutableStateFlow(false)
val isWebViewShowing: StateFlow<Boolean>
get() = _isWebViewShowing
fun onReadMoreClicked() {
_isWebViewShowing.value = true
}
fun changeWebViewState() {
_isWebViewShowing.value = false
}}
This my XML where I am doing the comparison
<?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="article"
type="io.infinity.newsapp.model.domain.ArticleDomainModel" />
<variable
name="viewModel"
type="io.infinity.newsapp.viewmodels.ArticleDetailsViewModel" />
<import type="android.view.View"/>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_generic"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:visibility="#{viewModel.isWebViewShowing().value ? View.INVISIBLE :View.VISIBLE }"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/toolbar"
app:layout_constraintStart_toStartOf="#+id/toolbar"
app:layout_constraintTop_toBottomOf="#+id/toolbar">
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
app:cardCornerRadius="#dimen/_20sdp"
android:layout_margin="#dimen/_16sdp"
android:layout_height="250dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
loadImageFromUrl="#{article.urlToImage}"
android:scaleType="centerCrop"/>
</com.google.android.material.card.MaterialCardView>
<TextView
android:id="#+id/textView"
style="#style/eighteen_sp_muli_bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_8sdp"
android:text="#{article.title}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_margin="#dimen/_16sdp"
android:orientation="horizontal"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvAuthor"
style="#style/twelve_sp_muli_extra_bold"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="start"
android:layout_marginStart="8dp"
android:text="#{article.author}"
android:textAllCaps="true"
android:textColor="#color/semi_black"
/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="#dimen/_4sdp"
android:layout_marginEnd="#dimen/_2sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="#+id/tvTitle"
app:srcCompat="#drawable/circle_blue" />
<TextView
android:id="#+id/tvSource"
style="#style/twelve_sp_muli_extra_bold"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="#{article.source.name}"
android:textAllCaps="true"
android:textColor="#color/semi_black"
app:layout_constraintBottom_toBottomOf="#+id/imageView2"
app:layout_constraintStart_toEndOf="#+id/imageView2"
app:layout_constraintTop_toTopOf="#+id/imageView2" />
<TextView
android:id="#+id/publishedOn"
android:gravity="end"
style="#style/twelve_sp_muli_extra_bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="8dp"
setDateAndTime="#{article.publishedAt}"
android:textAllCaps="true"
android:textColor="#color/semi_black"
/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
style="#style/fourteen_sp_muli_bold"
android:text="#{article.description}"
android:layout_marginStart="#dimen/_16sdp"
android:layout_marginEnd="#dimen/_16sdp"
android:layout_marginTop="#dimen/_16sdp"
android:layout_marginBottom="0dp"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/tvReadMore"
android:onClick="#{() -> viewModel.onReadMoreClicked()}"
android:layout_width="match_parent"
style="#style/twelve_sp_muli_regular"
android:text="#string/read_more"
android:textColor="#color/light_blue"
android:layout_marginStart="#dimen/_16sdp"
android:layout_height="wrap_content"/>
</LinearLayout>
<WebView
android:id="#+id/webView"
loadArticleInWeb="#{article.url}"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="#{viewModel.isWebViewShowing().value ? View.VISIBLE :View.INVISIBLE}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

Related

Recyclerview animation (layout change in size and margins after click)

Iam working on an app using recyclerview in which if I click an item, it will change in layout height(view will be visible) and margins changes.
How to animate like google dialer app when I click recent contact will show elevation layout and shrink margins?
I use notifyitemchange(position) and work in animate shift of point (left and top of layout).
but I want to animate shrink layout margins not shift view like google app dialer recent contacts [google app dialer].
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/groups_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="10dp"
android:paddingBottom="180dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
</LinearLayout>
viewholder layout
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="group"
type="com.example.gtt.database.Group" />
<variable
name="clickListener"
type="com.example.gtt.start.GroupListener" />
<variable
name="viewModel"
type="com.example.gtt.start.StartViewModel" />
</data>
<androidx.cardview.widget.CardView
android:id="#+id/cardView"
layoutMarginGroup="#{group}"
layoutMarginGroupId="#{viewModel.hideShowId}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
app:cardCornerRadius="6dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/itemLayout"
layoutBackColor="#{group}"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:onClick="#{() -> viewModel.onGroupHideShowClicked(group.groupId)}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/groupView"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginStart="#dimen/layoutMargin"
android:layout_marginTop="#dimen/layoutMargin"
android:layout_marginBottom="#dimen/layoutMargin"
android:background="#drawable/colored_circle"
android:gravity="center_horizontal|center_vertical"
android:onClick="#{() -> clickListener.onClick(group)}"
android:text="#{group.groupName.length >=2 ? group.groupName.substring(0,2).toUpperCase() : group.groupName.toUpperCase() }"
android:textAppearance="#style/TextAppearance.AppCompat.Display1"
android:textColor="#color/white"
app:layout_constraintEnd_toStartOf="#id/groupsTextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- android:text="#string/g" -->
<TextView
android:id="#+id/groupsTextView"
groupNameText="#{group}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:textColor="#color/colorBlue"
android:textSize="22sp"
app:layout_constraintBottom_toTopOf="#id/materialTextView"
app:layout_constraintEnd_toStartOf="#+id/cml"
app:layout_constraintStart_toEndOf="#id/groupView"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/materialTextView"
groupMaterialText="#{group}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#color/colorBlue"
android:textSize="22sp"
app:layout_constraintBottom_toTopOf="#id/appTextView"
app:layout_constraintEnd_toEndOf="#id/groupsTextView"
app:layout_constraintStart_toStartOf="#id/groupsTextView"
app:layout_constraintTop_toBottomOf="#+id/groupsTextView" />
<TextView
android:id="#+id/appTextView"
appText="#{group}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:textColor="#color/colorBlue"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="#+id/groupsTextView"
app:layout_constraintStart_toStartOf="#id/groupsTextView"
app:layout_constraintTop_toBottomOf="#+id/materialTextView" />
<LinearLayout
android:id="#+id/cml"
cmlBackColor="#{group}"
android:layout_width="wrap_content"
android:minWidth="70dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="#+id/appTextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/groupsTextView"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="#string/numberOfClasses"
android:textAlignment="center"
android:textSize="12sp" />
<TextView
android:id="#+id/classTextView"
classText="#{group}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textAlignment="center"
android:textColor="#color/colorBlue"
android:textSize="18sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="#string/numberOfMonths"
android:textAlignment="center"
android:textSize="12sp" />
<TextView
android:id="#+id/monthTextView"
monthText="#{group}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textAlignment="center"
android:textColor="#color/colorBlue"
android:textSize="18sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout2"
layoutVisibilityGroup="#{group}"
layoutVisibilityGroupId="#{viewModel.hideShowId}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/cLayout">
<!-- android:visibility="gone"
android:background="#drawable/shadow_border"
-->
<View
android:id="#+id/divider9"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="?android:attr/listDivider"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/addClassButton"
style="#style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:drawableTop="#drawable/ic_add_class"
android:onClick="#{() -> viewModel.addClass()}"
android:text="#string/c"
android:textColor="#color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/delClassButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/delClassButton"
style="#style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:drawableTop="#drawable/ic_del_class"
android:onClick="#{() -> viewModel.delClass()}"
android:text="#string/c"
android:textColor="#color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/addClassButton"
app:layout_constraintTop_toTopOf="#+id/addClassButton" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</layout>
binding adapter to change data and layout
#BindingAdapter("layoutVisibilityGroup", "layoutVisibilityGroupId")
fun ConstraintLayout.setLayoutVisibility(item: Group, id: Long) {
visibility = if (item.groupId == id) {
View.VISIBLE
} else {
View.GONE
}
}
#BindingAdapter("layoutMarginGroup","layoutMarginGroupId")
fun setLayoutMargin(view: CardView, item: Group, id: Long) {
if (view.layoutParams is ViewGroup.MarginLayoutParams) {
val p = view.layoutParams as ViewGroup.MarginLayoutParams
if (item.groupId == id) {
val npx = dpToPixel(10f).toInt()
p.setMargins(npx, p.topMargin, npx, p.bottomMargin)
} else {
p.setMargins(0, p.topMargin,0, p.bottomMargin)
}
//view.layoutParams = p
}
view.cardElevation = if (item.groupId == id) {
dpToPixel(8f)
} else {
0f
}
}
and I use this code to animate layout changes
adapter.notifyItemChanged(oldPosition)
adapter.notifyItemChanged(newPosition)

How to fill the rest of the screen with RecyclerVeiw?

In the image below you can see the RecyclerView extends below my screen. This is the reason why I can't see the last item. I want only my RecyclerView to be scrollable.
Can I solve this with the xml only?
This is my_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"
tools:context=".screens.mijnhuis.HuisFragment">
<data>
<import type="android.view.View"/>
<import type="android.text.TextUtils"/>
<variable
name="varName"
type="be.vives.ti.summatieve.screens.mijnhuis.HuisVM"/>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<TextView
android:id="#+id/adres"
style="#style/MainText"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_marginTop="50dp"
android:text='#{TextUtils.isEmpty(varName.huis.straat) ? "U heeft nog geen adres ingesgteld":#string/adres(varName.huis.straat, varName.huis.nummer, varName.huis.gemeente, varName.huis.postcode)}'
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button2"
style="#style/btn"
android:layout_marginStart="20dp"
android:onClick="#{() -> varName.btnNavToEditHuis()}"
android:text="#string/edit"
app:layout_constraintStart_toEndOf="#+id/button3"
app:layout_constraintTop_toBottomOf="#+id/adres" />
<Button
android:id="#+id/button3"
style="#style/btn"
android:layout_marginEnd="110dp"
android:onClick="#{() -> varName.btnNavToAdd()}"
android:text="#string/addDak"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/button2" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/list"
android:name="be.vives.ti.summatieve.HuisFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
app:layoutManager="LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button3"
tools:context=".screens.mijnHuis.HuisFragment"
tools:listitem="#layout/detail_dak" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
In this image, you can see that my RecyclerView extends under my screen.
Image
You are missing a bottom constraint. Try setting like this:
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/list"
android:name="be.vives.ti.summatieve.HuisFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
app:layoutManager="LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button3"
app:layout_constraintBottom_toBottomOf="parent"
tools:context=".screens.mijnHuis.HuisFragment"
tools:listitem="#layout/detail_dak" />
Welcome Bjop, try this:
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/list"
android:name="be.vives.ti.summatieve.HuisFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
app:layoutManager="LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button3"
tools:context=".screens.mijnHuis.HuisFragment"
tools:listitem="#layout/detail_dak" />

Android button outside of a text view

What is the best way to achieve the following UI where I want a button to appear "outside" and above a TextView?
Here's what I want to do (expected), the code I've written for it, and how it appears in my emulator (actual).
Expected: the "x" button is outside of the text view
My Layout:
(also, note: I'm inflating the bottom_sheet_layout in a class that extends com.google.android.material.bottomsheet.BottomSheetDialogFragment)
<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/bottom_sheet_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/blue">
<TextView
android:id="#+id/bottom_sheet_menu_delete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Delete"
android:textSize="15sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/bottom_sheet_x"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="#drawable/ic_cancel_24dp"
app:layout_constraintBottom_toTopOf="#id/bottom_sheet_menu_delete"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Actual:
change the layout_constraintBottom_toTopOf id of Button
move background from parent to TextView
<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/bottom_sheet_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<TextView
android:id="#+id/bottom_sheet_menu_delete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:background="#color/blue"//add background
android:text="Delete"
android:textSize="15sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/bottom_sheet_x"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="#drawable/ic_cancel_24dp"
app:layout_constraintBottom_toTopOf="#id/bottom_sheet_menu_delete"//change id
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<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/bottom_sheet_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/blue">
<Button
android:id="#+id/bottom_sheet_x"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="#drawable/ic_cancel_24dp"
app:layout_constraintBottom_toTopOf="#+id/bottom_sheet_menu_delete"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="#+id/bottom_sheet_menu_delete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Delete"
android:textSize="15sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
try this -->
<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/bottom_sheet_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<Button
android:id="#+id/bottom_sheet_x"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="#drawable/your_cross_image"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="MissingConstraints" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorAccent"
app:layout_constraintTop_toBottomOf="#id/bottom_sheet_x"
tools:ignore="MissingConstraints,NotSibling">
<TextView
android:id="#+id/bottom_sheet_menu_delete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Delete"
android:textSize="15sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

how to fix this category Layout Problems in Android App

I have a problem with the Category Layout in my App. The problem is that the next category starts in the next line. I want to show it a mixed layout. Not like another category will show below that category. Please help me to fix this issue. I have searched on the internet but don't know how to fix it.
item_category_list_adapter.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="allWallpaperByCategory"
type="com.panaceasoft.pswallpaper.viewobject.Category" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<androidx.constraintlayout.widget.ConstraintLayout
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">
<ImageView
android:id="#+id/itemImageView"
android:layout_width="0dp"
android:layout_height="0dp"
android:contentDescription="No Image"
android:scaleType="centerCrop"
app:imageUrl="#{allWallpaperByCategory.default_photo.img_path}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText"
tools:srcCompat="#drawable/app_icon" />
<View
android:id="#+id/view52"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#drawable/black_alpha_50"
app:layout_constraintBottom_toBottomOf="#+id/itemImageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/itemImageView"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/productCountTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="#string/category__30wallpaper"
android:textAlignment="viewStart"
android:textColor="#color/md_grey_400"
android:textSize="#dimen/font_body_size"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/categoryNameTextView"
tools:ignore="MissingConstraints" />
<TextView
android:id="#+id/categoryNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:textAlignment="viewStart"
android:textColor="#color/md_grey_300"
android:textSize="#dimen/font_h5_size"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/view52"
tools:ignore="MissingConstraints"
tools:text="20 Category" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
mybe you can do this in your item xml n in you recyclerview use layout manager gridview 2 coloums
Like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="5dp"
android:text="Demo Text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
android:text="Demo Text" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
android:text="Demo Text 2" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="5dp"
android:text="Demo Text" />
</LinearLayout>
</LinearLayout>
You have to generate custom layout using canvas.
Please go through the links
https://developer.android.com/training/custom-views/custom-drawing
https://medium.com/over-engineering/getting-started-with-drawing-on-the-android-canvas-621cf512f4c7
https://medium.com/mindorks/how-to-create-custom-views-141dc0570e57

Progress bar show under Button

Android studio 3.1
minSdkVersion 21
Here my layout 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="handler"
type="md.dotfinance.tm.android.ui.activity.AddTraderActivity" />
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/common_gray_color_bg">
<include
android:id="#+id/jsonViewToolBar"
layout="#layout/tool_bar"
android:title='#{#string/add_trader}'
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/baseTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/default_margin"
android:layout_marginEnd="8dp"
android:text="#string/base"
android:textSize="13sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/jsonViewToolBar" />
<EditText
android:id="#+id/baseEditText"
style="#style/textViewOneLine"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="#+id/baseTextView"
app:layout_constraintStart_toStartOf="#+id/baseTextView"
app:layout_constraintTop_toBottomOf="#+id/baseTextView" />
<TextView
android:id="#+id/quoteTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/default_margin"
android:text="#string/quote"
android:textSize="13sp"
app:layout_constraintEnd_toEndOf="#+id/baseTextView"
app:layout_constraintStart_toStartOf="#+id/baseTextView"
app:layout_constraintTop_toBottomOf="#+id/baseEditText" />
<EditText
android:id="#+id/quoteEditText"
style="#style/textViewOneLine"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="13sp"
app:layout_constraintEnd_toEndOf="#+id/baseTextView"
app:layout_constraintStart_toStartOf="#+id/baseTextView"
app:layout_constraintTop_toBottomOf="#+id/quoteTextView" />
<Button
android:id="#+id/startButton"
android:layout_width="0dp"
android:layout_height="#dimen/min_height"
android:layout_marginTop="#dimen/default_margin"
android:layout_marginBottom="#dimen/default_margin"
android:background="#color/button_gray"
android:text="#string/start"
app:layout_constraintEnd_toEndOf="#+id/baseTextView"
app:layout_constraintStart_toStartOf="#+id/baseTextView"
app:layout_constraintTop_toBottomOf="#+id/quoteEditText" />
<include
layout="#layout/progress_bar_layout"
android:visibility="gone" />
</android.support.constraint.ConstraintLayout>
</layout>
Here my progress_bar_layout.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:id="#+id/containerProgressBarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4777"
android:clickable="true"
android:focusable="true">
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="48dp"
android:layout_height="48dp"
android:indeterminateTint="#color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
But when I start app the progress bar is UNDER button.
But I need over button.
How I can do this?
Try to use
of
android.support.constraint.ConstraintLayout
and add
android:elevation="30dp"
to the RelativeLayout tag
The best way to do this is to hide the progress bar or make it's visibility="gone". Make sure you give it an ID so you can invoke it and hide the other layout with buttons and text views. Then show the progress bar when you process a certain request. Make it invisible!!!
Try that
<?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="handler"
type="md.dotfinance.tm.android.ui.activity.AddTraderActivity" />
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="#layout/progress_bar_layout"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/common_gray_color_bg">
<include
android:id="#+id/jsonViewToolBar"
layout="#layout/tool_bar"
android:title='#{#string/add_trader}'
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/baseTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/default_margin"
android:layout_marginEnd="8dp"
android:text="#string/base"
android:textSize="13sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/jsonViewToolBar" />
<EditText
android:id="#+id/baseEditText"
style="#style/textViewOneLine"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="#+id/baseTextView"
app:layout_constraintStart_toStartOf="#+id/baseTextView"
app:layout_constraintTop_toBottomOf="#+id/baseTextView" />
<TextView
android:id="#+id/quoteTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/default_margin"
android:text="#string/quote"
android:textSize="13sp"
app:layout_constraintEnd_toEndOf="#+id/baseTextView"
app:layout_constraintStart_toStartOf="#+id/baseTextView"
app:layout_constraintTop_toBottomOf="#+id/baseEditText" />
<EditText
android:id="#+id/quoteEditText"
style="#style/textViewOneLine"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="13sp"
app:layout_constraintEnd_toEndOf="#+id/baseTextView"
app:layout_constraintStart_toStartOf="#+id/baseTextView"
app:layout_constraintTop_toBottomOf="#+id/quoteTextView" />
<Button
android:id="#+id/startButton"
android:layout_width="0dp"
android:layout_height="#dimen/min_height"
android:layout_marginTop="#dimen/default_margin"
android:layout_marginBottom="#dimen/default_margin"
android:background="#color/button_gray"
android:text="#string/start"
app:layout_constraintEnd_toEndOf="#+id/baseTextView"
app:layout_constraintStart_toStartOf="#+id/baseTextView"
app:layout_constraintTop_toBottomOf="#+id/quoteEditText" />
</android.support.constraint.ConstraintLayout>
</layout>

Categories

Resources