1 year ago
#176856
Pedro Montesinos Navarro
Update view elements after transition change on android
I've got a transition on the app I'm developing that fades all elements of a frame layout and swaps them for other elements. The animation works as intended, but from there I can't interact with the buttons on the new scene applied to the fragment. Here is the relevant parts of the code:
This is the frame layout where the animation happens
<FrameLayout
android:id="@+id/scene_root_index"
android:layout_width="match_parent"
android:layout_height="360dp"
app:layout_constraintBottom_toTopOf="@+id/indexSearchButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView4">
<include layout="@layout/main_scene" />
</FrameLayout>
This is the main_scene:
<!--[...]-->
<ImageButton
android:id="@+id/newsMainIndexBtn"
android:layout_width="100dp"
android:layout_height="100dp"
android:backgroundTint="#00FFFFFF"
android:contentDescription="@string/descripcion_boton_noticias"
app:layout_constraintTop_toBottomOf="@+id/imageView6"
app:srcCompat="@drawable/ic_noticias"
tools:layout_editor_absoluteX="59dp" />
<!--[...]-->
This is the news scene, here is where I need the back button to work:
<!--[...]-->
<ImageButton
android:id="@+id/newsBack"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backgroundTint="#00FFFFFF"
app:srcCompat="@drawable/ic_back" />
<!--[...]-->
This is the onCreateView method I'm using
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
setMainActivity((MainActivity) getActivity());
View view = inflateFragment(R.layout.fragment_index, inflater, container);
assert view != null;
sceneRoot = (ViewGroup) view.findViewById(R.id.scene_root_index);
mainScene = Scene.getSceneForLayout(sceneRoot, R.layout.main_scene, getActivity());
newsScene = Scene.getSceneForLayout(sceneRoot, R.layout.news_scene, getActivity());
transitionManagerForIndexScene = TransitionInflater.from(getActivity()).inflateTransitionManager(R.transition.transition_manager_for_index_scene, sceneRoot);
AppCompatImageButton news = view.findViewById(R.id.newsMainIndexBtn);
news.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
TransitionManager.go(newsScene);
}
});
The only solution that I've been able concieve is to make another layout with the same elements as the main one swapping out the frameView, but that animates all the screen and I feel like this is the correct way to do it, but I'm missing something.
I've tried to create the onclick event for the button everywhere in the code, but I couldn't find a place or time when the code recognized it, instead giving me a null pointer exception everytime.
Thanks for your time and for the help, I'm looking forward to be able to solve this issue.
java
android
android-layout
android-transitions
0 Answers
Your Answer