appbar_scrolling_view_behavior not resolved at SwipeRefreshLayout databinding android - android-databinding

I try to add the app:layout_behavior="#string/appbar_scrolling_view_behavior" to the SwipeRefreshLayout but I don't know why i isn't resolved at XML layout although It works properly after running the codes. Does this matter with data binding and MVVM?
<?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="ir.basamadazmanovin.heartrate.ui.main.home.HomeViewModel" />
</data>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:onRefreshListener="#{()-> viewModel.onRefresehing()}"
app:refreshing="#{viewModel.isLoading}">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/fragment_home_recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="3" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="#+id/fragment_home_toolbar"
style="#style/Toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:subtitleTextColor="#color/material_white"
app:title="#string/app_name"
app:titleTextAppearance="#style/Toolbar.TitleText"
app:titleTextColor="#color/material_white" />
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
implementation "com.google.android.material:material:1.0.0"
app:layout_behavior="#string/appbar_scrolling_view_behavior" is red and the IDE mentions "Unresolved class '#string/appbar_scrolling_view_behavior' less... (Ctrl+F1) Inspection info: Validates resource references inside Android XML files."

Use this instead:
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">

Related

My findViewById is not working. in my fragment

My findViewById is not working. it does not link...
////my fragment.contacts.xml
*<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="#+id/txtShowOnMap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:contentDescription="#string/locationonmap"
android:importantForAutofill="no"
android:inputType="text"
android:labelFor="#id/btnShowOnMap"
android:minHeight="48dp"
android:text="#string/store_location" />
<Button
android:id="#+id/btnShowOnMap"
android:layout_width="395dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="#string/map" />
</LinearLayout>*
////end of fragmentcontacts.xml
my contactsfragment.kt
Please Make it view.findViewById
For fragment you need to add rootview.

fix The last item falls under FloatingActionButton and does not scroll completely

thank you for helping me solve this problem
I created the following BottomNavigationView code but my problem is that the last item in the middle of FloatingActionButton falls and the scrolling is not complete
xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/Athens_Gray"
tools:context=".ui.MainActivity">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bottombar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:fabAlignmentMode="center"
app:fabAnimationMode="scale"
app:fabCradleMargin="#dimen/_10sdp"
app:fabCradleRoundedCornerRadius="#dimen/_20sdp"
android:background="#android:color/transparent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/_16sdp"
android:layout_marginRight="#dimen/_16sdp"
android:background="#android:color/transparent"
app:labelVisibilityMode="unlabeled"
app:menu="#menu/bottom_nav" />
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="TODO"
android:src="#drawable/ic_add_square_outline"
app:backgroundTint="#color/Deluge"
app:layout_anchor="#id/bottomNavigation"
app:tint="#color/white" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/nav_graph"
android:paddingBottom="#dimen/_60sdp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
According to the screenshot below
screenshot

Unable to move from one fragment to another

I am trying to set up an activity with a fragment with a recyclerview and a botom navigation menu. When I tap on the 'Dashboard', I can see the progress bar and it updates the data from Firestore but when I hit the Quizzes I cannot see the progress bar or new data. All I am seeing is the same data. I think it's not moving to other fragment.
As a beginner I do not know the actual working of fragments and recyclerview I am doing it with the help of people and resources available online.
I couldn't figure out where the problem is. I can provide more codes if needed.
NOTE: I am not getting any error.
bottom_nav_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_dashboard"
android:icon="#drawable/ic_vector_dashboard"
android:title="Dashboard" />
<item
android:id="#+id/navigation_quizzes"
android:icon="#drawable/ic_vector_quizzes"
android:title="Quizzes" />
</menu>
mobile_navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation 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/mobile_navigation"
app:startDestination="#+id/navigation_dashboard">
<fragment
android:id="#+id/navigation_dashboard"
android:name="com.example.quiz.ui.fragments.DashboardFragment"
android:label="#string/title_dashboard"
tools:layout="#layout/fragment_dashboard" />
<fragment
android:id="#+id/navigation_quiz"
android:name="com.example.quiz.ui.fragments.QuizFragment"
android:label="#string/title_products"
tools:layout="#layout/fragment_quiz" />
</navigation>
activity_dashboard.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"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="#drawable/app_gradient_color_background"
app:itemIconTint="#color/colorWhite"
app:itemTextColor="#color/colorWhite"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/bottom_nav_menu" />
<androidx.fragment.app.FragmentContainerView
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="#id/nav_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:navGraph="#navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
fragment_dashboard.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="match_parent"
android:background="#color/white"
tools:context=".ui.fragments.DashboardFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_dashboard_items"
tools:listitem="#layout/item_list_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/tv_no_dashboard_items_found"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="no_dashboard_item_found"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
fragment_quiz.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="match_parent"
android:background="#color/white"
tools:context=".ui.fragments.QuizFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvQuizzesFrag"
tools:listitem="#layout/item_list_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/tv_no_products_found"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="NO QUIZZES TODAY"
android:textAlignment="center"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
DashboardActivity.kt
package com.example.quiz.ui.activities
import android.os.Bundle
import androidx.core.content.ContextCompat
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.example.quiz.R
class DashboardActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dashboard)
supportActionBar!!.setBackgroundDrawable(
ContextCompat.getDrawable(
this#DashboardActivity,
R.drawable.app_gradient_color_background
)
)
val navView: BottomNavigationView = findViewById(R.id.nav_view)
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navController = navHostFragment.navController
val appBarConfiguration = AppBarConfiguration(
setOf(
R.id.navigation_quiz,
R.id.navigation_dashboard
)
)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
}
override fun onBackPressed() {
doubleBackToExit()
}
}
Can you tell me where these R.id.navigation_quiz, R.id.navigation_dashboard should be referring to? Whether to the bottom_nav_menu.xml or mobile_navigation.xml.
If you think it's not moving to Quiz Fragment then it might be because your BottomNavigation is not working correctly....
For bottom navigation to work correct with Nav Controller the id's of items in bottom_nav_menu.xml and moile_navigation.xml must be same
In your case the id of dashboard is same in bottom_nav_menu.xml and moile_navigation.xml but for quiz the id's are different in both of these files, it is #+id/navigation_quizzes in bottom_nav_menu.xml and in moile_navigation.xml it is #+id/navigation_quiz
Make the id's same in both files
bottom_nav_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_dashboard"
android:icon="#drawable/ic_vector_dashboard"
android:title="Dashboard" />
<item
android:id="#+id/navigation_quiz"
android:icon="#drawable/ic_vector_quiz"
android:title="Quizzes" />
</menu>
moile_navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation 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/mobile_navigation"
app:startDestination="#+id/navigation_dashboard">
<fragment
android:id="#+id/navigation_dashboard"
android:name="com.example.quiz.ui.fragments.DashboardFragment"
android:label="#string/title_dashboard"
tools:layout="#layout/fragment_dashboard" />
<fragment
android:id="#+id/navigation_quiz"
android:name="com.example.quiz.ui.fragments.QuizFragment"
android:label="#string/title_products"
tools:layout="#layout/fragment_quiz" />
</navigation>

How to scroll recyclerview with Image or ImageSlider

Please help me.
I can't scroll image with recyclerview.
XML:
<?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:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#drawable/pattern"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/app_bar_main">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="#drawable/line" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/main_swipe"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/rc"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
//Have a bit of a problem with the ImageView
//ScrollView but not working.
You can use linearlayout's layout weight:
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/main_swipe"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/rc"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
/>
</android.support.v4.widget.SwipeRefreshLayout>

Floating action button with CoordinatorLayout

I using fragments in my app. I have base activity with hiding toolbar when content is scrolling. But is not working with this fragment. FAB is hiding ok but toolbar is not hiding when i scrolling. FAB and list not fitting bottom. How to do that? Thx.
Sorry for my English please.
Activity layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/coordinator"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|enterAlways">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="0dp"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/app_nav_header_main"
app:menu="#menu/main_drawer" />
</android.support.v4.widget.DrawerLayout>
Fragment layout:
<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/flipper"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="#layout/layout_please_wait"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/adsList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/addAds"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:src="#drawable/ic_action_new"
app:layout_anchor="#id/adsList"
app:layout_anchorGravity="bottom|right|end"
app:layout_behavior="sakh.com.utils.ScrollAwareFABBehavior"
app:useCompatPadding="true" />
</android.support.design.widget.CoordinatorLayout>
<include
layout="#layout/layout_no_internet"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
layout="#layout/layout_no_search_result"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</ViewFlipper>