Tôi đang cố gắng tìm hiểu công việc TransitionManager đơn giản, nhưng tôi bị kẹt một chút ...onClick không hoạt động sau khi chuyển đổi
Mục tiêu của tôi là thay đổi giữa hai cảnh bằng cách nhấp vào hình ảnh. Nhưng sau khi nhấp chuột hình ảnh đầu tiên và thay đổi cảnh đầu tiên, tôi không thể bắt hình ảnh nhấp chuột ...
đây là đoạn mã của tôi:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
ViewGroup sceneRoot = (ViewGroup)rootView.findViewById(R.id.relative);
final Transition transition = new ChangeBounds();
transition.setDuration(3000);
final Scene scene1 = Scene.getSceneForLayout(sceneRoot, R.layout.scene1, getActivity());
final Scene scene2 = Scene.getSceneForLayout(sceneRoot, R.layout.scene2, getActivity());
ImageView image = (ImageView)rootView.findViewById(R.id.image);
image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!testBoo){
TransitionManager.go(scene2, transition);
testBoo = true;
} else {
testBoo = false;
TransitionManager.go(scene1, transition);
}
}
});
return rootView;
}
đoạn xml:
<RelativeLayout
android:id="@+id/relative"
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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:showIn="@layout/activity_main"
tools:context=".MainActivityFragment">
<include
layout="@layout/scene1"
/>
</RelativeLayout>
Scene 1 xml:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/text"
android:text="Hello World!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/image"
android:layout_margin="5dp"
/>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_alignParentTop="true"
/>
</RelativeLayout>
cảnh2 xml:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/text"
android:text="Hello World!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:layout_alignParentBottom="true"
android:layout_toStartOf="@id/image"
/>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
Bạn có biết mình đang đi sai ở đâu không?
tìm thấy câu trả lời nào chưa? –