I am trying to make a transition like this one that scales a grid layouts cardview child (which is inside a fragment) to another cardview inside the new fragment.
I have followed all the instructions on the android guide and have no progress. I don't know what I am doing wrong or what I have misunderstood.
Here are the relevant pieces of code.
fragment_small_ad_page.xml
<RelativeLayout 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"
android:paddingHorizontal="15.7dp"
tools:context=".SmallAdPage"
android:animateLayoutChanges="true">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/smallAdRecyclerView"
android:layout_width="match_parent"
android:layout_height="530dp"
android:layout_marginTop="40dp"
android:layout_marginBottom="30dp"
tools:listitem="#layout/recyclerview_ad_image_item"
/>
<fragment
android:id="#+id/appFragment"
android:name="com.example.hubosandroid.AppsFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/smallAdRecyclerView"/>
</RelativeLayout>
fragment_apps.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".AppsFragment">
<GridLayout
android:id="#+id/apps_grid_layout"
android:layout_below="#id/smallAdRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="5"
android:rowCount="8"
android:animateLayoutChanges="true">
<androidx.cardview.widget.CardView
android:id="#+id/first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowSpan="2"
android:layout_rowWeight="2"
android:layout_columnSpan="1"
android:layout_columnWeight="1"
android:layout_margin="5dp"
app:cardBackgroundColor="#color/yellow"
app:cardCornerRadius="10dp">
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowSpan="2"
android:layout_rowWeight="2"
android:layout_columnSpan="1"
android:layout_columnWeight="1"
android:layout_margin="5dp"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="10dp"></androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/third"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowSpan="4"
android:layout_rowWeight="4"
android:layout_columnSpan="2"
android:layout_columnWeight="2"
android:layout_margin="5dp"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="10dp">
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/fourth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowSpan="4"
android:layout_rowWeight="4"
android:layout_columnSpan="1"
android:layout_columnWeight="1"
android:layout_margin="5dp"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="10dp">
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/fifth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowSpan="2"
android:layout_rowWeight="2"
android:layout_columnSpan="2"
android:layout_columnWeight="2"
android:layout_margin="5dp"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="10dp">
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/sixth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowSpan="1"
android:layout_rowWeight="1"
android:layout_columnSpan="2"
android:layout_columnWeight="2"
android:layout_margin="5dp"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="10dp">
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/seventh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowSpan="2"
android:layout_rowWeight="2"
android:layout_columnSpan="3"
android:layout_columnWeight="3"
android:layout_margin="5dp"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="10dp">
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/eighth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowSpan="1"
android:layout_rowWeight="1"
android:layout_columnSpan="2"
android:layout_columnWeight="2"
android:layout_margin="5dp"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="10dp">
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/ninth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowSpan="2"
android:layout_rowWeight="2"
android:layout_columnSpan="5"
android:layout_columnWeight="5"
android:layout_margin="5dp"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="10dp">
</androidx.cardview.widget.CardView>
</GridLayout>
</FrameLayout>
fragment_game_selection.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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/teal_200"
tools:context=".ui.mainActivity.fragments.GameSelectionFragment">
<androidx.cardview.widget.CardView
android:id="#+id/appCard"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/hello_blank_fragment" />
</androidx.cardview.widget.CardView>
</FrameLayout>
AppsFragment.kt
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentAppsBinding.inflate(layoutInflater)
val view = binding.root
binding.appsGridLayout.forEach {
ViewCompat.setTransitionName(it as CardView, it.id.toString())
it.setOnClickListener {
parentFragmentManager.commit {
val newScreen = GameSelectionFragment()
setReorderingAllowed(true)
addSharedElement(it as CardView, "scale_transition")
replace(R.id.appFragment, newScreen)
addToBackStack(null)
}
}
}
return view
}
GameSelectionFragment.kt
class GameSelectionFragment : Fragment() {
private lateinit var binding: FragmentGameSelectionBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
sharedElementEnterTransition = TransitionInflater.from(requireContext())
.inflateTransition(R.transition.scale_transition.xml)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
postponeEnterTransition()
binding = FragmentGameSelectionBinding.inflate(layoutInflater)
val view = binding.root
ViewCompat.setTransitionName(binding.appCard, "scale_transition")
startPostponedEnterTransition()
return view
}
}
scale_transition.xml
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300">
<changeBounds/>
<changeTransform/>
</transitionSet>
Would appreciate any help. Thanks.
Related
I am Trying to Achieve the Exposed Drop-Down Menu in Android I have tried this one but can't identify where I went wrong.
DropDown_item.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textview.MaterialTextView
android:id="#+id/textViewFeelings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:text="TextView"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
</androidx.appcompat.widget.LinearLayoutCompat>
BottomSheetDialogConnectWifiFragment.kt
class BottomSheetDialogConnectWifiFragment : BottomSheetDialogFragment() {
private lateinit var _binding: FragmentBottomSheetDialogConnectWifiBinding
private val items = listOf("Material", "Design", "Components", "Android")
private lateinit var ActivityContext: Context
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onAttach(context: Context) {
ActivityContext = context
super.onAttach(context)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentBottomSheetDialogConnectWifiBinding.inflate(inflater, container, false)
return _binding.root
//
// val arrayAdapter = ArrayAdapter(_binding.root.context, R.layout.dropdown_item, items)
// _binding.autoCompleteTextFieldSsidType.setAdapter(arrayAdapter)
_binding.autoCompleteTextFieldSsidType.apply {
setAdapter(
ArrayAdapter(
ActivityContext,
R.layout.dropdown_item,
items
)
)
}
}
companion object {
const val TAG = "CustomBottomSheetDialogFragment"
}
}
fragment_bottom_sheet_dialog_connect_wifi
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView 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:padding="10dp"
tools:context=".Fragments.BottomSheetDialogConnectWifiFragment">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<androidx.cardview.widget.CardView
android:layout_width="100dp"
android:layout_height="2dp"
android:layout_centerHorizontal="true"
android:elevation="10dp"
android:foregroundGravity="center_vertical"
app:cardBackgroundColor="#color/black"
app:cardCornerRadius="100dp">
<!--YOUR CONTENT-->
</androidx.cardview.widget.CardView>
<com.google.android.material.textview.MaterialTextView
android:id="#+id/idTVCourseTracks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Add Network"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="15sp" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilSsid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/idTVCourseTracks"
android:keyboardNavigationCluster="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter The SSID" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textFieldSsidType"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tilSsid"
android:layout_marginTop="12dp">
<AutoCompleteTextView
android:id="#+id/autoCompleteTextFieldSsidType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Enter The SSID"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textFieldPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textFieldSsidType"
android:layout_marginTop="12dp">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="#+id/idBtnDismiss"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textFieldPassword"
android:layout_marginTop="12dp"
android:text="Connect"
android:textAllCaps="false"
android:theme="#style/ShapeAppearanceOverlay.Material3.Button" />
</RelativeLayout>
</ScrollView>
</com.google.android.material.card.MaterialCardView>
I Created An bottomSheet in Android/kotlin and trying to solve this cant understood where i missing some thing to
i have try with .Apply{}Method And also with the normally but both of them not worked for me
I have a Navigation drawer that has four different fragments. On the Home Fragment Dashboard, I have eight different image buttons that I want to open a new activity I.E. when you click the Image Button TM's I want it to open the TM's activity. I'm using kotlin as well.
I've watched numerous videos and forums on YouTube and google and none have seemed to work for what I'm doing.
// Dashboard.kt is where I have my ImageButtons, where I want each button to open a new activity.
package com.example.militarymainenance
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
class Dashboard : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_dashboard, container, false)
}
}
// fragment_dashboard.xml is where I have my ImageButtons, where I want each button to open a new activity.
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
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"
tools:context=".Dashboard">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="32dp"
android:layout_marginRight="20dp">
<ImageView
android:id="#+id/txtdashboard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/dashboard3"
android:textAlignment="center"
android:textColor="#FFF" />
</RelativeLayout>
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:rowCount="3"
android:columnCount="2"
android:alignmentMode="alignMargins">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="#color/material_on_surface_stroke"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:gravity="center">
<ImageButton
android:id="#+id/card1"
android:src="#drawable/folder3"
android:scaleType="centerCrop"
android:layout_width="130dp"
android:layout_height="130dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:textColor="#color/white"
android:text="#string/tm_s"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardBackgroundColor="#color/material_on_surface_stroke"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:gravity="center">
<ImageButton
android:id="#+id/card2"
android:src="#drawable/circuit3"
android:scaleType="centerCrop"
android:layout_width="130dp"
android:layout_height="130dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:textColor="#color/white"
android:text="#string/schematics"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardBackgroundColor="#color/material_on_surface_stroke"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:gravity="center">
<ImageButton
android:id="#+id/card3"
android:src="#drawable/parts3"
android:scaleType="centerCrop"
android:layout_width="130dp"
android:layout_height="130dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:textColor="#color/white"
android:text="#string/parts_cheat_sheet"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardBackgroundColor="#color/material_on_surface_stroke"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:gravity="center">
<ImageButton
android:id="#+id/card4"
android:src="#drawable/load3"
android:scaleType="centerCrop"
android:layout_width="130dp"
android:layout_height="130dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:textColor="#color/white"
android:text="#string/generator_load_wiring"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
// MainActivity.kt which controls my navigation drawer.
package com.example.militarymainenance
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.core.view.GravityCompat
import androidx.fragment.app.Fragment
import com.google.android.material.navigation.NavigationView
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.content_main.*
class MainActivity : AppCompatActivity(),NavigationView.OnNavigationItemSelectedListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
val toggle = ActionBarDrawerToggle(this,drawerLayout,toolbar,R.string.open,R.string.close)
toggle.isDrawerIndicatorEnabled = true
drawerLayout.addDrawerListener(toggle)
toggle.syncState()
nav_menu.setNavigationItemSelectedListener(this)
setToolbarTitle("Dashboard")
changeFragment(Dashboard())
}
override fun onNavigationItemSelected(item: MenuItem): Boolean {
drawerLayout.closeDrawer(GravityCompat.START)
when(item.itemId){
R.id.dashboard -> {
setToolbarTitle("Dashboard")
changeFragment(Dashboard())
}
R.id.equipment_tracker -> {
setToolbarTitle("Equipment Tracker")
changeFragment(Equipment_tracker())
}
R.id.service_tracker -> {
setToolbarTitle("Service Tracker")
changeFragment(Service_tracker())
}
R.id.faults_tracker -> {
setToolbarTitle("Faults Tracker")
changeFragment(Faults_tracker())
}
R.id.share -> {
setToolbarTitle("Service Tracker")
changeFragment(Service_tracker())
}
R.id.rate_us -> {
setToolbarTitle("Faults Tracker")
changeFragment(Faults_tracker())
}
}
return true
}
fun setToolbarTitle(title:String){
supportActionBar?.title = title
}
fun changeFragment(frag:Fragment){
val fragment = supportFragmentManager.beginTransaction()
fragment.replace(R.id.fragment_container,frag).commit()
}
}
// activity_main.xml which controls my navigation bar
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#515050"
tools:context=".MainActivity">
<include layout="#layout/content_main" />
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/navigation_header"
app:menu="#menu/navigation_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
You should create ImageButton view in your xml file, then bind onClickListener to it and call startActivity when onClick triggers.
just an example to understand:
public class TabFragment1 extends Fragment {
ImageButton imageButton;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_tab_fragment1, container, false);
imageButton = (ImageButton)view.findViewById(R.id.imageButton);
imageButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(getActivity(),NewActivity.class);
}
});
return view;}
I'd to show the user cards horizontally using a RecyclerView, but I have a problem like the image below.
The card not appears at first, but when I scroll it a little bit, the card shows up suddenly. It looks really weird. Why don't the card rendered from the starts? And it's the same case for the other end of the RecyclerView.
I'm suspecting the clipChildren or clipToPadding. Is there any solution to this problem without having to put the categories outside of the LinearLayout with a padding?
HomeFragment.kt
class HomeFragment : Fragment() {
private lateinit var binding: FragmentHomeBinding
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentHomeBinding.inflate(inflater, container, false)
val view = binding.root
setupCategories()
setupProducts()
return view
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
private fun setupCategories() {
val dummy = arrayOf(
Category(R.drawable.shoes_nike_black),
Category(R.drawable.yellow_shirt),
Category(R.drawable.hoodie_gray_big),
Category(R.drawable.hoodie_pink),
)
val spacingInPixels = (Resources.getSystem().displayMetrics.density * 8).toInt()
binding.includeContentMain.recyclerViewCategories.addItemDecoration(
LinearSpacingItemDecoration(spacingInPixels)
)
binding.includeContentMain.recyclerViewCategories.adapter = CategoriesAdapter(dummy)
}
// other unrelated code...
}
content_main.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:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:paddingLeft="25dp"
android:paddingTop="15dp"
android:paddingRight="30dp"
android:paddingBottom="15dp"
tools:showIn="#layout/fragment_home">
<TextView
android:id="#+id/textViewCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginBottom="12dp"
android:text="Category"
android:textSize="30dp" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:fillViewport="true">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerViewCategories"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
android:nestedScrollingEnabled="false"
android:orientation="horizontal"
android:overScrollMode="always"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="4"
tools:listitem="#layout/item_card_category" />
</androidx.core.widget.NestedScrollView>
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginBottom="12dp"
android:text="Top Selling"
android:textSize="30dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerViewTopSelling"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"
tools:itemCount="6"
tools:listitem="#layout/item_card_product">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
item_card_category.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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="150dp"
android:layout_height="150dp"
app:cardBackgroundColor="#F7BE30"
app:cardCornerRadius="10dp">
<ImageView
android:id="#+id/imageViewCategory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:padding="10dp"
android:src="#drawable/bag"
tools:src="#tools:sample/backgrounds/scenic" />
</androidx.cardview.widget.CardView>
That line of code will help. For JAVA and KOTLIN use:
recyclerViewCategories.getRecycledViewPool().setMaxRecycledViews(0, 0);
*recyclerViewCategories = recyclerView
I have a fragment in which I have a spinner and checkbox.
The layout file need_help_fragment_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/all_fragment_background"
android:clickable="true"
android:focusable="true">
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/parent_top"
app:layout_constraintGuide_percent="0"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/parent_bottom"
app:layout_constraintGuide_percent="1"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/parent_left"
android:orientation="vertical"
app:layout_constraintGuide_percent="0"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/parent_right"
android:orientation="vertical"
app:layout_constraintGuide_percent="1"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/top_title_bottom"
app:layout_constraintGuide_percent=".25"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/top_title_bottom"
app:layout_constraintEnd_toStartOf="#+id/parent_right"
app:layout_constraintStart_toEndOf="#+id/parent_left"
app:layout_constraintTop_toBottomOf="#+id/parent_top">
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/text_view_top"
app:layout_constraintGuide_percent="0"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/text_view_bottom"
app:layout_constraintGuide_percent="1"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/text_view_left"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.07"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/text_view_right"
android:orientation="vertical"
app:layout_constraintGuide_percent=".93"/>
<TextView
android:text="#string/need_help_header_text"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:id="#+id/title_header_text_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#+id/text_view_top"
app:layout_constraintBottom_toTopOf="#+id/text_view_bottom"
app:layout_constraintStart_toEndOf="#+id/text_view_left"
app:layout_constraintEnd_toStartOf="#+id/text_view_right"
android:textColor="#color/all_text_color"
android:textSize="18sp"
android:gravity="center">
</TextView>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/mid_content_bottom_guide"
app:layout_constraintGuide_percent=".8"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#+id/top_title_bottom"
app:layout_constraintBottom_toTopOf="#+id/mid_content_bottom_guide"
app:layout_constraintStart_toEndOf="#+id/parent_left"
app:layout_constraintEnd_toStartOf="#+id/parent_right">
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/mid_content_top"
app:layout_constraintGuide_percent="0"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/mid_content_bottom"
app:layout_constraintGuide_percent="1"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/mid_content_left"
android:orientation="vertical"
app:layout_constraintGuide_percent=".07"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/mid_content_right"
android:orientation="vertical"
app:layout_constraintGuide_percent=".93"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/spinner_bottom"
app:layout_constraintGuide_percent=".2"
android:orientation="horizontal"/>
<androidx.appcompat.widget.AppCompatSpinner
android:background="#null"
app:layout_constraintTop_toBottomOf="#+id/mid_content_top"
app:layout_constraintBottom_toTopOf="#+id/spinner_bottom"
app:layout_constraintStart_toEndOf="#+id/mid_content_left"
app:layout_constraintEnd_toStartOf="#+id/mid_content_right"
android:id="#+id/spinner_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center_horizontal | bottom"
android:text="3 Seconds"
android:textColor="#color/all_text_color"
android:textSize="22sp" />
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/checkbox_top"
app:layout_constraintGuide_percent=".4"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/checkbox_bottom"
app:layout_constraintGuide_percent=".6"
android:orientation="horizontal"/>
<CheckBox
android:layout_width="0dp"
android:layout_height="0dp"
android:text="Remove timing, Auto Mode"
app:layout_constraintTop_toBottomOf="#+id/checkbox_top"
app:layout_constraintBottom_toTopOf="#+id/checkbox_bottom"
app:layout_constraintStart_toEndOf="#+id/mid_content_left"
app:layout_constraintEnd_toStartOf="#+id/mid_content_right"
android:layoutDirection="rtl"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:textSize="18sp"
android:textColor="#color/all_text_color"
android:id="#+id/remove_timing_auto_mode_check_box"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Code in fragment:
class NeedHelpFragment: Fragment(), View.OnClickListener {
lateinit var homeActivity : MainActivity
var check_box: CheckBox? = null
var spinner_view: Spinner? = null
lateinit var timeSpinnerList: ArrayList<String>
lateinit var timeSpinnerAdapter: ArrayAdapter<String>
override fun onAttach(context: Context) {
super.onAttach(context)
if(context is MainActivity)
homeActivity = context
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
var v : View = inflater.inflate(R.layout.need_help_fragment_layout, container, false)
check_box = v.findViewById<CheckBox>(R.id.check_box)
timeSpinnerList = ArrayList()
for(i in 0..10)
timeSpinnerList.add("$i seconds")
timeSpinnerAdapter = ArrayAdapter(homeActivity, android.R.layout.simple_spinner_dropdown_item, timeSpinnerList)
spinner_view = v.findViewById<Spinner>(R.id.spinner_view)
spinner_view!!.adapter = timeSpinnerAdapter
return v
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
override fun onClick(view: View?) {
when(view!!.id){
}
}
}
The color code:
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>
<color name="all_text_color">#6F6F6F</color>
<color name="all_fragment_background">#F8F8F8</color>
When anything is not selected it is fine:
When an item is selected from the spinner, the checkbox disappears:
There is nothing else in the layout file. Just the constraint layout and the guidelines for the checkbox and spinner. The spinner and the checkbox are initialized in the onCreateView of the fragment. The checkbox disappears when I select any item from the spinner. Please help.
I think the problem is about your setting value about constraintLayout options like :
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/spinner_view"
app:layout_constraintBottom_toBottomOf="parent"
I think that was wrong in some cases.
Then for simple example i removed guidelines and i solved it.
You can use this approach and add your guidelines.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/all_fragment_background"
android:clickable="true"
android:focusable="true">
<TextView
android:id="#+id/title_header_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="HEAD"
android:textColor="#color/all_text_color"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatSpinner
android:id="#+id/spinner_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:background="#null"
android:gravity="center_horizontal|bottom"
android:text="3 Seconds"
android:textColor="#color/all_text_color"
android:textSize="22sp"
app:layout_constraintBottom_toTopOf="#+id/remove_timing_auto_mode_check_box"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/title_header_text_view" />
<CheckBox
android:id="#+id/remove_timing_auto_mode_check_box"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layoutDirection="rtl"
android:paddingLeft="10dp"
android:text="Remove timing, Auto Mode"
android:textColor="#color/all_text_color"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/spinner_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
I am an amateur in android studio and kotlin. I am implementing a dashboard where I have frame layout as the bodylayout and is replaced by different fragments when each item on the bottomnavigationview is clicked. However, for one particular item I need to use two view, imageview and a scrollview. So, when the progress bar in the scrollview contains no progress, I have to show the Imageview hiding the scrollview and also disabling the scroll at that time. But When there is some progress in the progressbar in the scrollview, scrollview with it's content should be shown and not the imageview.
I have seen some answers int he same context but it didn't work for me. So, I would like to know how to do it? Am I doing it wrong.
The code snippet is below.
class ProgressFragment : Fragment() {
val TAG = "ProgressFragment"
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_progress, container, false)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
progress_progressbar2?.setProgress(5)
progress_progressbar2?.max=15
if (progress_progressbar2?.progress!!.equals(0)){
started_image?.bringToFront()
progress_scrollview?.invalidate()
}
else{
progress_scrollview?.bringToFront()
started_image?.invalidate()
navigation_header_container?.setImageResource(R.drawable.header_pink)
}
}
}
I am calling this fragment in the mainactivity and replacing the framelayout with this fragment in the mainactivity.
The activity_main.xml layout is given below.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main"
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="#mipmap/bg"
tools:context=".MainActivity">
<ImageView
android:id="#+id/navigation_header_container"
android:layout_width="match_parent"
android:layout_height="65dp"
android:scaleY="1.5"
android:scaleX="2"
android:src="#drawable/header_green"
/>
<FrameLayout
android:id="#+id/main_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="75dp"
android:layout_above="#id/bottom_nav"
android:layout_alignParentStart="true"
android:layout_below="#+id/navigation_header_container"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:itemBackground="#color/colorWhite"
app:itemTextColor="#color/nav_item_colors"
app:menu="#menu/bottom_navigation">
</android.support.design.widget.BottomNavigationView>
<TextView
android:id="#+id/header_text"
android:layout_width="156dp"
android:layout_height="39dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:gravity="center"
android:textSize="20dp"
android:textColor="#200"
android:textStyle="bold"
android:text="TextView" />
<!--app:itemIconTint="#color/nav_item_colors"-->
<!--app:itemTextColor="#color/nav_item_colors"-->
</RelativeLayout>
The progress layout is given below.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ProgressFragment">
<!-- TODO: Update blank fragment layout -->
<ScrollView
android:id="#+id/progress_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/progress_parentrelayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/progress_child1relayout"
android:layout_width="190dp"
android:layout_height="280dp">
<TextView
android:id="#+id/quadrant1_textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60sp"
android:layout_marginTop="90dp"
android:gravity="center"
android:text="Min"
android:textColor="#200"
android:textSize="18sp"
android:textStyle="bold" />
<ProgressBar
android:id="#+id/progress_progressbar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="35dp"
android:layout_marginTop="140dp"
android:progressDrawable="#drawable/customprogressbar" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/progress_child2relayout"
android:layout_width="190dp"
android:layout_height="280dp"
android:layout_below="#+id/progress_child1relayout">
<TextView
android:id="#+id/quadrant2_textview1"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40sp"
android:layout_marginStart="40sp"
android:layout_marginTop="70dp"
android:text="Challenge Status"
android:textColor="#200"
android:textSize="18sp"
android:textStyle="bold" />
<ProgressBar
android:id="#+id/progress_progressbar2"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginStart="40dp"
android:layout_marginTop="160dp"
android:progressDrawable="#drawable/customprogressbar" />
<TextView
android:id="#+id/quadrant2_textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="42dp"
android:layout_marginTop="130dp"
android:text="Completed"
android:textColor="#200"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/quadrant2_textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_marginTop="190dp"
android:text="open"
android:textColor="#200"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/quadrant2_textview4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_marginTop="230dp"
android:text="0"
android:textColor="#200"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/progress_child3relayout"
android:layout_width="190dp"
android:layout_height="280dp"
android:layout_toRightOf="#+id/progress_child1relayout">
<TextView
android:id="#+id/quadrant3_textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60sp"
android:layout_marginTop="90dp"
android:gravity="center"
android:text="TextView"
android:textColor="#200"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/progress_child4relayout"
android:layout_width="190dp"
android:layout_height="280dp"
android:layout_below="#id/progress_child3relayout"
android:layout_toRightOf="#+id/progress_child2relayout">
<TextView
android:id="#+id/quadrant4_textview1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="60sp"
android:layout_marginTop="70dp"
android:text="Pods Mastered"
android:textColor="#200"
android:textSize="18sp"
android:textStyle="bold" />
<me.zhanghai.android.materialprogressbar.MaterialProgressBar
android:id="#+id/circularprogress"
android:layout_width="150dp"
android:layout_height="70dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="130dp"
android:progress="20" />
<!--<ProgressBar-->
<!--android:id="#+id/progress_progressbar3"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_marginTop="120dp"-->
<!--android:layout_marginLeft="50sp"-->
<!--android:indeterminateDrawable="#drawable/ringprogressbar"-->
<!--android:max="100"-->
<!--android:progress="20"-->
<!--style="?android:attr/progressBarStyleLarge" />-->
</RelativeLayout>
<TextView
android:id="#+id/whatdoesthis_mean"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_marginTop="580dp"
android:clickable="true"
android:gravity="center"
android:text="What does this mean?"
android:textColor="#200"
android:textSize="15dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/child_button"
android:layout_width="344dp"
android:layout_height="79dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="620dp"
android:src="#drawable/pinkcolor"
android:text="child name" />
<TextView
android:id="#+id/child_name_text"
android:layout_width="184dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="11dp"
android:fontFamily="sans-serif"
android:gravity="center"
android:text="Child Name"
android:textColor="#190fdf"
android:textSize="30sp"
android:textStyle="bold" />
</RelativeLayout>
</ScrollView>
<ImageView
android:id="#+id/started_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/letsgetstarted"
android:background="#ebcac3c7"
/>
</FrameLayout>
Any help is appreciated.
Fragments don't create the view in OnCreate unlike the Activity. The same can be understood through the life-cycle of a fragment. Moreover, this is one of the major differences between an activity life-cycle and a fragment life-cycle. So, instead of assigning the values in the OnCreate, it should be done in OnViewCreated.
The code snippet could be modified to:
class ProgressFragment : Fragment() {
val TAG = "ProgressFragment"
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_progress, container, false)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
progress_progressbar2?.setProgress(12)
progress_progressbar2?.max=15
val currentProgress = progress_progressbar2?.progress ?: 0
if (currentProgress == 0){
started_image?.visibility = View.VISIBLE
progress_scrollview?.visibility = View.GONE
} else {
started_image?.visibility = View.GONE
progress_scrollview?.visibility = View.VISIBLE
navigation_header_container?.setImageResource(R.drawable.header_pink)
}
}
}
The condition and static/dynamic progress assignment can be done in the OnResume method also.
Thank you Vishnu.
val currentProgress = progress_progressbar2?.progress ?: 0
if (currentProgress == 0){
started_image?.visibility = VISIBLE
progress_scrollview?.visibilty = GONE
} else {
started_image?.visibility = GONE
progress_scrollview?.visibilty = VISIBLE
navigation_header_container?.setImageResource(R.drawable.header_pink)
}
Instead of bringToFront you manage it using the visibility of the views.
Android Documentation : https://developer.android.com/reference/android/view/View.html#setVisibility(int)
Try this out