Android 我在NavigationDrawer活动中有一个带有自定义工具栏的片段。如何在活动中从片段到工具栏设置图像动画
我在同一活动布局的ActivityStarting和destination中成功地制作了动画。但我希望它从子片段过渡到其父活动工具栏中的布局。下面给出了我用来制作动画的代码 工具栏xml布局Android 我在NavigationDrawer活动中有一个带有自定义工具栏的片段。如何在活动中从片段到工具栏设置图像动画,android,animation,fragment,android-toolbar,Android,Animation,Fragment,Android Toolbar,我在同一活动布局的ActivityStarting和destination中成功地制作了动画。但我希望它从子片段过渡到其父活动工具栏中的布局。下面给出了我用来制作动画的代码 工具栏xml布局 <android.support.v7.widget.Toolbar android:id="@+id/products_toolbar" android:layout_width="wrap_content" android:layout_height="?attr/actionBarSize" a
<android.support.v7.widget.Toolbar android:id="@+id/products_toolbar"
android:layout_width="wrap_content"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
app:layout_collapseMode="pin"
app:titleTextColor="@android:color/white"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:id="@+id/cartRelativeLayout"
android:layout_width="0dp"
android:layout_weight=".15"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:clickable="true"
android:paddingRight="3dip">
<ImageButton
android:id="@+id/cartButtonIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:clickable="false"
android:src="@drawable/cart" />
<TextView
android:id="@+id/textNotify"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/cartButtonIV"
android:layout_alignTop="@id/cartButtonIV"
android:layout_marginRight="5dip"
android:layout_marginTop="5dip"
android:background="@drawable/notification_circle"
android:gravity="center"
android:minHeight="20dip"
android:minWidth="20dip"
android:padding="3dip"
android:text="0"
android:textColor="#424242"
android:textSize="12sp" />
</RelativeLayout>
在下面的CircleAnimationUtil.class方法中,即使我从makeFlyAnimation函数向视图传递活动,也会将视图设置为null
public CircleAnimationUtil setTargetView(View view) {
Log.e("view here",""+view);
mTarget = view;
setOriginRect(mTarget.getWidth(), mTarget.getHeight());
return this;
}
任何人请给我一个解决方案 使用目标片段来实现这一点,如
public class First extends Fragment{
public void startSecondFragmentForResult(){
Fragment second = Second.newInstance()
second.setTargetFragment(this);
fm.beginTranstaction().replace(second).commit();
}
@Override
public void onActivityResult(int reqCode, int resCode, Intent data){
// do something on result
}
}
第二段
你不能那样做。如果要在片段之间通信,请参阅。或者也有很多关于这个话题的讨论。
public class First extends Fragment{
public void startSecondFragmentForResult(){
Fragment second = Second.newInstance()
second.setTargetFragment(this);
fm.beginTranstaction().replace(second).commit();
}
@Override
public void onActivityResult(int reqCode, int resCode, Intent data){
// do something on result
}
}
public class Second extends Fragment{
public void postResultToCaller(){
Intent intent = new Intent();
getTargetFragment().onActivityResult(getTargetRequestCode(), resultCode, intent);
}
}