i create custom attribute use by BindingAdapter,but it unable to use in layout
BindingAdapter
#BindingAdapter("android:killAble")
fun View.setKillAble(killAble: Boolean) {
this.isEnabled = killAble
}
layout
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/et_height"
android:killAble="true"
android:layout_marginTop="32dp"
app:layout_constraintTop_toBottomOf="#+id/et_name"
android:layout_marginStart="16dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginRight="16dp"
/>
HomeFragment.kt
class HomeFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val binding: FragmentHomeBinding = DataBindingUtil.inflate(inflater,
R.layout.fragment_home, container, false)
val rootView = binding.root
val viewmodel=ViewModelProviders.of(this).get(HomeViewModel::class.java)
binding.lifecycleOwner = this
binding.viewModel = viewmodel
return rootView
}
}
please help me
You must use the data binding syntax:
android:killAble="#{true}"
Related
I need to implement ProgressDialogFragment which extends DialogFragment. Before showing I should set the text to the dialog fragment. Here's my layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ProgressBar
android:id="#+id/pb_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:progressDrawable="#drawable/progressbar"
android:theme="#style/ProgressBar" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/tv_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_toEndOf="#id/pb_loading"
tools:text="Loading text" />
</RelativeLayout>
Here's my class ProgressDialogFragment:
class ProgressDialogFragment : DialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.progress_dialog_fragment, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
tv_message?.text = requireArguments().getString("message", "")
}
companion object {
fun newInstance(message: String) = ProgressDialogFragment().apply {
arguments = bundleOf(Pair("message", message))
}
}
}
So, as you can see, now I am creating a new instance each time when I should show the dialog. But is there any way to set the message to the object which already exists? I tried to add the method setMessage which sets message to textview and not to use the new instance in this case, but I caught an exception that textview for the message is not initialized. So, are there any ways to solve my problem?
I have a LoginActivity in which there are two fragments. Using the navigation library, I switch between these fragments. But now I need to go from the fragment to another Activity. My code doesn't work for some reason, there are no errors in logCat. When I used this code with Activity everything works well. Is it all about a fragment or the navigation library?
My ViewModel
class AuthViewModel #Inject constructor(private var mAuth: FirebaseAuth) : ViewModel() {
var mEmail: String = ""
var mPassword: String = ""
var loginListener: LoginListener? = null
fun login(view: View) {
if (mEmail.isNotEmpty() && mPassword.isNotEmpty()) {
mAuth = FirebaseAuth.getInstance()
mAuth.signInWithEmailAndPassword(mEmail, mPassword).addOnCompleteListener {
if (it.isSuccessful) {
loginListener?.startLoading()
android.os.Handler().postDelayed({
loginListener?.endLoading()
loginListener?.validateLoginAndPassword()
}, 500)
} else {
loginListener?.showError(textResource = R.string.login_error)
}
}
} else {
loginListener?.showError(textResource = R.string.login_or_password_empty)
}
}
}
My Fragment
class LoginFragment : DaggerFragment(), View.OnClickListener, KeyboardVisibilityEventListener, LoginListener {
private lateinit var navController: NavController
lateinit var binding: FragmentLoginBinding
#Inject
lateinit var factory: ViewModelProvider.Factory
lateinit var mAuthViewModel: AuthViewModel
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
binding = FragmentLoginBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
navController = Navigation.findNavController(view)
view.btn_registration.setOnClickListener(this)
mAuthViewModel = ViewModelProviders.of(this#LoginFragment, factory).get(AuthViewModel::class.java)
}
override fun onClick(view: View?) {
when(view!!.id) {
R.id.btn_registration -> navController.navigate(R.id.action_loginFragment_to_registerFragment)
}
}
override fun validateLoginAndPassword() {
//startActivity(Intent(activity, ContactListActivity::class.java))
val intent = Intent(activity, ContactListActivity::class.java)
startActivity(intent)
}
My LoginFragment XML
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="loginViewModel"
type="com.infernal93.phonebookappmvvmanddagger.viewmodels.AuthViewModel" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
tools:context=".view.fragments.LoginFragment">
<ScrollView
android:id="#+id/root_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true" >
<EditText
android:id="#+id/login_email"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp"
android:background="#drawable/bg_inputs"
android:ems="10"
android:hint="#string/email_text"
android:text="#={loginViewModel.mEmail}"
android:inputType="textEmailAddress"
android:textColorHint="#color/dark_gray" />
<EditText
android:id="#+id/login_password"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_below="#id/login_email"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:background="#drawable/bg_inputs"
android:hint="#string/password_text"
android:text="#={loginViewModel.mPassword}"
android:inputType="textPassword"
android:textColorHint="#color/dark_gray" />
<com.github.rahatarmanahmed.cpv.CircularProgressView
android:id="#+id/cpv_login"
android:layout_width="#dimen/cpv_size"
android:layout_height="#dimen/cpv_size"
android:layout_below="#id/login_password"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:visibility="gone"
app:cpv_animAutostart="true"
app:cpv_color="#color/colorPrimary"
app:cpv_indeterminate="true" />
<Button
android:id="#+id/btn_login_enter"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_below="#id/cpv_login"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="#drawable/bg_buttons"
android:text="#string/login_btn_text"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="#dimen/login_btns_text_size"
android:onClick="#{(view) -> loginViewModel.login(view)}"/>
<Button
android:id="#+id/btn_registration"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_below="#id/btn_login_enter"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="#drawable/bg_buttons"
android:text="#string/registration_btn_text"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="#dimen/login_btns_text_size" />
</RelativeLayout>
</ScrollView>
</FrameLayout>
</layout>
You didn't bind ViewModel with View. Use below:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
navController = Navigation.findNavController(view)
view.btn_registration.setOnClickListener(this)
mAuthViewModel = ViewModelProviders.of(this#LoginFragment, factory).get(AuthViewModel::class.java)
//Bind viewmodel
binding.loginViewModel = mAuthViewModel
}
I forgot to specify LoginListener in the fragment
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
//return inflater.inflate(R.layout.fragment_login, container, false)
binding = FragmentLoginBinding.inflate(inflater, container, false)
mAuthViewModel = ViewModelProviders.of(this#LoginFragment, factory).get(AuthViewModel::class.java)
binding.loginViewModel = mAuthViewModel
// LoginListener
mAuthViewModel.loginListener = this
return binding.root
}
So I've been searching on internet for a while already now but I just can't seem to find the correct topic to help me out with this.
I have the following code which is relevant for this question:
This is my adapter class.
class SmoelenBoekAdapter(var profiles: Array<Profile>) : RecyclerView.Adapter<CustomViewHolder>(){
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
val layout = layoutInflater.inflate(com.otten.nvvofrankversie.R.layout.recyclerview_smoelenboek, parent, false)
return CustomViewHolder(layout)
}
override fun onBindViewHolder(holder: CustomViewHolder, position: Int) {
val positioner = profiles.get(position)
var profileImage = positioner.profile_image
var firstName = positioner.first_name
var lastName = positioner.last_name
var plaats = positioner.place
var adres = positioner.address
holder.view.naamSmoelenBoek.text = firstName.string + " " + lastName.string
}
override fun getItemCount(): Int {
return profiles.size
}
}
class CustomViewHolder(val view: View) : RecyclerView.ViewHolder(view)
This is my 'MainActivity' (for this particular fragment)
class SmoelenBoek : ApplicationFragment(){
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_smoelenboek, null)
}
/*override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
smoelenboekRecyclerView.adapter = SmoelenBoekAdapter(profiles)
}*/
}
xml where adapterinfo has to be filled in:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/profielPicSmoelenBoek"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/business_icon" />
<TextView
android:id="#+id/naamSmoelenBoek"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="Frank Otten"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="#+id/profielPicSmoelenBoek"
app:layout_constraintStart_toEndOf="#+id/profielPicSmoelenBoek"
app:layout_constraintTop_toBottomOf="#+id/profielPicSmoelenBoek" />
<TextView
android:id="#+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:text=">"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/naamSmoelenBoek" />
</androidx.constraintlayout.widget.ConstraintLayout>
And this is the fragment where I have a recyclerview in which needs to be filled with the above 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:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/imageView8"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/offer_bg"
android:adjustViewBounds="true"
android:scaleType="center"/>
<Button
android:id="#+id/searchInSmoelenBoek"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="60dp"
android:layout_marginEnd="15dp"
android:background="#color/lightGray"
android:hint="Zoek in smoelenboek"
android:padding="10dp"
android:textAlignment="textStart"
android:textColor="#color/colorAccent"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="60dp"
android:text="Vind gemakkelijk alle\naangesloten orthodontisten"
android:textColor="#color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/searchInSmoelenBoek" />
<TextView
android:id="#+id/textView15"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:text="Aangesloten orthodontisten"
android:textAlignment="textStart"
android:textColor="#color/browser_actions_title_color"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView8" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/smoelenboekRecyclerView"
android:layout_width="409dp"
android:layout_height="440dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView15"/>
</androidx.constraintlayout.widget.ConstraintLayout>
What am I doing wrong or missing here?
I think I still need to set the adapter correctly, but I can't figure that out either...
Hope anyone can help me!
// Set layout manager for recycler view
smoelenboekRecyclerView.layoutManager = LinearLayoutManager(this);
// Set adapter to recycler view
smoelenboekRecyclerView.adapter = SmoelenBoekAdapter(profiles)
class CustomViewHolder(val view: View) : RecyclerView.ViewHolder(view){
val tvNaamSmolText = view.naamSmoelenBoek
}
override fun onBindViewHolder(holder: CustomViewHolder, position: Int) {
val positioner = profiles.get(position)
var profileImage = positioner.profile_image
var firstName = positioner.first_name
var lastName = positioner.last_name
var plaats = positioner.place
var adres = positioner.address
holder.tvNaamSmolText.text = firstName.string + " " + lastName.string
}
Try this
class SmoelenBoek : ApplicationFragment(){
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
View view = inflater.inflate(R.layout.fragment_smoelenboek, null)
view.smoelenboekRecyclerView.layoutManager = LinearLayoutManager(this);
view.smoelenboekRecyclerView.adapter = SmoelenBoekAdapter(profiles)
return view
}
}
}
class SmoelenBoek : ApplicationFragment(){
var profiles: Array<Profile> = arrayOf()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_smoelenboek, null)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
SharedInstance.api.getAllUsers {
profiles = it
smoelenboekRecyclerView.layoutManager = LinearLayoutManager(context)
smoelenboekRecyclerView.adapter = SmoelenBoekAdapter(profiles)
}
}
}
This is the solution to my problem.
I had to put the layoutmanager and adapter in OnviewCreated AFTER the async call (which I forgot to implement so that was part of the problem first) so the layoutmanager could be set and the adapter could fill my recyclerview with items.
Thanks for the help anyways guys!
I am trying to access a Floating Action Button inside a fragment but for some reason, I cannot. I keep getting errors. I have tried everything and nothing seems to work. Here is the code inside my fragment:
import android.os.Bundle
import android.support.design.widget.FloatingActionButton
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.FirebaseDatabase
import com.ntx_deisgns.cyberchatter.cyberchatter.Message
import com.ntx_deisgns.cyberchatter.cyberchatter.R
import kotlinx.android.synthetic.main.groups.*
import kotlinx.android.synthetic.main.groups2.*
class groups2 : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
// inflater.inflate(R.layout.groups2, container, false)
val fab = R.id.fab as FloatingActionButton
fab.setOnClickListener {
if (!mainActivityEditText.text.toString().isEmpty()){
sendData()
}else{
// Toast.makeText(this, "Please enter a message", Toast.LENGTH_SHORT).show()
}
}
return inflater.inflate(R.layout.groups2, container, false)
}
private fun sendData(){
val editText = groupInput
val database = FirebaseDatabase.getInstance()
val myRef = database.getReference("message")
myRef.setValue(Message(editText.text.toString()))
val mDatabase: DatabaseReference? = null
mDatabase?.
child("messages")?.
child(java.lang.String.valueOf(System.currentTimeMillis()))?.
setValue(Message(editText.text.toString()))
//clear the text
editText.setText("")
}
companion object {
fun newInstance(): groups2 = groups2()
}
}
What am I doing wrong? Why is it so hard to access a setOnClickListener within a fragment?
UPDATE:
Here's my groups2.xml:
<?xml version="1.0" encoding="utf-8"?>
<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:id="#+id/groups2_relative"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="60dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="55dp"
tools:context="com.ntx_deisgns.cyberchatter.cyberchatter.MainActivity">
<android.support.design.widget.FloatingActionButton
android:id="#+id/myFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:clickable="true"
android:focusable="true"
android:src="#drawable/ic_send_black_24dp"
android:tint="#android:color/white"
app:fabSize="mini" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_toStartOf="#id/myFab">
<EditText
android:id="#+id/groupInput"
android:layout_width="match_parent"
android:layout_height="57dp"
android:hint="Please enter your text here" />
</android.support.design.widget.TextInputLayout>
<ListView
android:id="#+id/list_of_messages"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/myFab"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="16dp"
android:divider="#android:color/transparent"
android:dividerHeight="16dp" />
</RelativeLayout>
You need to inflate the view before calling findViewById on it. Accessing the floating action button before inflation is causing the null pointer exception.
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
//inflate and store view
val view = inflater.inflate(R.layout.groups2, container, false)
val fab = view.findViewById(R.id.fab) as FloatingActionButton
//If using kotlinx then above line is not needed
fab.setOnClickListener {
//do your thing...
}
return view
}
I have two Fragments hosted in one Activity. They are dead simple:
class OneFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
val view = inflater.inflate(R.layout.fragment_one, container, false)
val sharedView = view.findViewById<View>(R.id.shared_view)
ViewCompat.setTransitionName(sharedView, "test")
view.findViewById<Button>(R.id.go_button).setOnClickListener {
val fragmentTransaction = fragmentManager.beginTransaction()
val oneFragment = fragmentManager.findFragmentById(R.id.fragment_container_frame_layout)
val twoFragment = TwoFragment()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val moveTransition = TransitionInflater.from(activity).inflateTransition(android.R.transition.move)
oneFragment.exitTransition = Fade()
val transitionSet = TransitionSet()
transitionSet.addTransition(TransitionInflater.from(activity).inflateTransition(android.R.transition.move))
transitionSet.duration = 600
twoFragment.sharedElementEnterTransition = transitionSet
twoFragment.enterTransition = Fade()
fragmentTransaction.addToBackStack(TwoFragment::class.java.simpleName)
fragmentTransaction.addSharedElement(sharedView, "test")
fragmentTransaction.replace(R.id.fragment_container_frame_layout, twoFragment)
fragmentTransaction.commit()
}
else {
fragmentTransaction.addToBackStack(TwoFragment::class.java.simpleName)
fragmentTransaction.replace(R.id.fragment_container_frame_layout, twoFragment)
fragmentTransaction.commit()
}
}
return view
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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="com.kravtsov.transitiontest.MainActivity">
<View
android:id="#+id/shared_view"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_centerInParent="true"
android:background="#android:color/holo_blue_dark" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/shared_view"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="HELLO"
tools:ignore="HardcodedText" />
<Button
android:id="#+id/go_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="GO"
tools:ignore="HardcodedText" />
</RelativeLayout>
And the second one:
class TwoFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
val view = inflater.inflate(R.layout.fragment_two, container, false)
val sharedView = view.findViewById<View>(R.id.shared_view)
ViewCompat.setTransitionName(sharedView, "test")
return view
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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="com.kravtsov.transitiontest.MainActivity">
<View
android:id="#+id/shared_view"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_below="#+id/anchor"
android:layout_centerHorizontal="true"
android:background="#android:color/holo_blue_dark" />
<TextView
android:id="#+id/anchor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="WORLD"
tools:ignore="HardcodedText" />
</RelativeLayout>
As you can see they have common shared view, that i want to animate during transition. The problem is - animation never appears. I can see that enter and exit fade transition for the rest of elements working correctly. Only shared element transition do not work.
I've searched web a lot and mimic a lot of guiedes... No answers i found still. Does anyone face such an issue? Where shoud i start to fix this bug?
Your code is working for me. I've used your layout and kotlin code, and it works seamlessly. One thing I took care of is importing all classes of support packages.