1

重要信息:

这些是我的动画:

R.anim.fragment_animation_in:

<!-- The info window in animation -->
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <alpha
        android:duration="500"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />        

</set>

R.anim.fragment_animation_out:

<?xml version="1.0" encoding="utf-8"?>
<!-- The info window in animation -->
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <alpha
        android:duration="500"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" />

</set>

我正在使用它们来平滑地更改我的片段:

/**
 * Show a new fragment
 * @param fragmentTransaction the fragment transaction, if null the a new {@link FragmentTransaction} will recevie from {@link FragmentManager}
 * @param fragment the new fragment to show
 * @param addToBackStack true if you wish to add the fragment to the back stack, false otherwise
 * @param toCommit true if you with to run the commit() method at the end of the transaction, false otherwise
 */
public void showFragment(FragmentTransaction fragmentTransaction,Fragment fragment, boolean addToBackStack, boolean toCommit)
{
    if (fragmentTransaction == null)
        fragmentTransaction = getSupportFragmentManager().beginTransaction();
    //set fragment changing animation
    fragmentTransaction.setCustomAnimations(R.anim.fragment_animation_in, R.anim.fragment_animation_out);
    //add the first fragment        
    fragmentTransaction.replace(MainActivity.APPLICATION_LAYOUT_ID, fragment);
    //if needed add to back stack
    if (addToBackStack)
        fragmentTransaction.addToBackStack(null);
    if (toCommit)
        //commit transaction
        fragmentTransaction.commit();
}

这是我的第一个布局:

<?xml version="1.0" encoding="utf-8"?>
<!-- Start fragment of the application -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.coapps.pico"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center_vertical"
    android:gravity="center"
    android:orientation="vertical" >

    <!-- logo -->

    <ImageView
        android:id="@+id/fragment_start_pico_logo"
        android:layout_width="wrap_content"
        android:layout_height="230dp"
        android:contentDescription="@string/app_name"
        android:src="@drawable/pico_logo" />

    <!-- start now button -->

    <LinearLayout
        android:id="@+id/fragment_start_linearlayout_start_now"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/fragment_start_pico_logo"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="60dp"
        android:background="@drawable/button_orange"
        android:clickable="true"
        android:gravity="center"
        android:orientation="horizontal"
        android:padding="15dp" >

        <!-- facebook logo -->

        <ImageView
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center"
            android:contentDescription="@string/app_name"
            android:scaleType="fitXY"
            android:src="@drawable/facebook_logo" />

        <!-- button text -->

        <com.coapps.pico.NillanTextView
            style="@style/text_shadow_black"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="20dp"
            android:gravity="center"
            android:text="@string/button_start_now"
            android:textColor="@android:color/white"
            android:textSize="30sp"
            app:isBold="true" />
    </LinearLayout>

</RelativeLayout>

这是我的第二个布局:

<?xml version="1.0" encoding="utf-8"?>
<!-- Home fragment layout -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.coapps.pico"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <!-- title layout -->

    <RelativeLayout
        android:id="@+id/fragment_home_relativelayout_title"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/fragment_home_linearlayout_statistics"
        android:background="@drawable/background_fragment_title"
        android:paddingBottom="5dp" >

        <!-- profile picture -->

        <ImageView
            android:id="@+id/fragment_home_imageview_profile_picture"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:background="@drawable/background_profile_picture"
            android:contentDescription="@string/app_name"
            android:scaleType="fitXY"
            android:src="@drawable/test_pic" />

        <!-- user name -->

        <com.coapps.pico.NillanTextView
            android:id="@+id/fragment_home_textview_user_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/fragment_home_imageview_profile_picture"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@+id/fragment_home_imageview_profile_picture"
            android:gravity="top"
            android:text="Roi Mozer"
            android:textColor="@android:color/white"
            android:textSize="30sp"
            app:isBold="true" />

        <!-- picash icon -->

        <ImageView
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_alignBottom="@+id/fragment_home_textview_picash"
            android:layout_marginLeft="10dp"
            android:layout_toLeftOf="@+id/fragment_home_textview_picash"
            android:contentDescription="@string/app_name"
            android:scaleType="fitXY"
            android:src="@drawable/icon_picash" />

        <!-- picash textview -->

        <com.coapps.pico.NillanTextView
            android:id="@+id/fragment_home_textview_picash"
            style="@style/text_shadow_black"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_marginRight="10dp"
            android:gravity="top"
            android:text="10"
            android:textColor="@color/orange"
            android:textSize="20sp"
            app:isBold="true" />
    </RelativeLayout>

    <!-- event statistics layout -->

    <LinearLayout
        android:id="@+id/fragment_home_linearlayout_statistics"
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:layout_above="@+id/fragment_home_view_orange_delimiter"
        android:background="@android:color/white"
        android:baselineAligned="false"
        android:orientation="horizontal" >

        <!-- Created Events Statistics Layout -->

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1" >

            <!-- created name -->

            <com.coapps.pico.NillanTextView
                android:id="@+id/fragment_home_textview_created_events_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:text="@string/labal_created_events"
                android:textColor="@color/text_grey_blue"
                android:textSize="15sp"
                app:isBold="true" />

            <!-- created number -->

            <com.coapps.pico.NillanTextView
                android:id="@+id/fragment_home_textview_created_events_number"
                style="@style/text_shadow_black"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:text="6"
                android:textColor="@color/orange"
                android:textSize="60sp"
                app:isBold="true" />
        </RelativeLayout>
        <!-- Invited Events Statistics Layout -->

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1" >

            <!-- invited name -->

            <com.coapps.pico.NillanTextView
                android:id="@+id/fragment_home_textview_invited_events_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:text="@string/labal_invited_events"
                android:textColor="@color/text_grey_blue"
                android:textSize="15sp"
                app:isBold="true" />

            <!-- invited number -->

            <com.coapps.pico.NillanTextView
                android:id="@+id/fragment_home_textview_invited_events_number"
                style="@style/text_shadow_black"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:text="6"
                android:textColor="@color/orange"
                android:textSize="60sp"
                app:isBold="true" />
        </RelativeLayout>
        <!-- Attending Events Statistics Layout -->

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1" >

            <!-- attending name -->

            <com.coapps.pico.NillanTextView
                android:id="@+id/fragment_home_textview_attending_events_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:text="@string/labal_attending_events"
                android:textColor="@color/text_grey_blue"
                android:textSize="15sp"
                app:isBold="true" />

            <!-- attending number -->

            <com.coapps.pico.NillanTextView
                android:id="@+id/fragment_home_textview_attending_events_number"
                style="@style/text_shadow_black"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:gravity="center"
                android:text="6"
                android:textColor="@color/orange"
                android:textSize="60sp"
                app:isBold="true" />
        </RelativeLayout>
    </LinearLayout>

    <!-- orange delimiter -->

    <View
        android:id="@+id/fragment_home_view_orange_delimiter"
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:layout_above="@+id/fragment_home_relativelayout_tutorial"
        android:background="@color/orange" />

    <!-- tutorial video layout -->

    <RelativeLayout
        android:id="@+id/fragment_home_relativelayout_tutorial"
        android:layout_width="fill_parent"
        android:layout_height="170dp"
        android:layout_above="@+id/fragment_home_textview_logout"
        android:layout_margin="5dp" >

        <!-- tutorial video -->

        <VideoView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

        <!-- Triangle shape -->

        <ImageView
            android:layout_width="100dp"
            android:layout_height="96dp"
            android:layout_centerInParent="true"
            android:contentDescription="@string/app_name"
            android:scaleType="fitXY"
            android:src="@drawable/shape_triangle" />
        <!-- tutorial video textview -->

        <com.coapps.pico.NillanTextView
            style="@style/text_shadow_black"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="@string/labal_tutorial_video"
            android:textColor="@android:color/white"
            android:textSize="25sp"
            app:isBold="true" />
    </RelativeLayout>

    <!-- logout -->

    <com.coapps.pico.NillanTextView
        android:id="@+id/fragment_home_textview_logout"
        style="@style/text_shadow_black"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_margin="10dp"
        android:layout_marginTop="10dp"
        android:clickable="true"
        android:text="@string/button_logout"
        android:textColor="@android:color/white"
        android:textSize="20sp"
        app:isBold="true" />

</RelativeLayout>

这是我的第三个布局:

<?xml version="1.0" encoding="utf-8"?>
<!-- enter code fragment of the application -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.coapps.pico"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background_start"
    android:gravity="center" >

    <!-- event code -->

    <EditText
        android:id="@+id/fragment_event_code_edittext_event_code"
        style="@style/text_shadow_black"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:background="@drawable/background_edittext_grey"
        android:ellipsize="end"
        android:gravity="center"
        android:hint="@string/hint_enter_code"
        android:inputType="number"
        android:padding="15dp"
        android:singleLine="true"
        android:textColor="@android:color/white"
        android:textColorHint="@android:color/white"
        android:textSize="25sp" />

    <!-- Load Event -->

    <com.coapps.pico.NillanTextView
        android:id="@+id/fragment_event_code_textview_load_event"
        style="@style/text_shadow_black"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/fragment_event_code_edittext_event_code"
        android:layout_gravity="center"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="15dp"
        android:background="@drawable/button_orange"
        android:clickable="true"
        android:gravity="center"
        android:padding="15dp"
        android:text="@string/button_load_event"
        android:textColor="@android:color/white"
        android:textSize="25sp"
        app:isBold="true" />

</RelativeLayout>

问题:

当我尝试从第一个布局更改为第二个布局时,动画不流畅,第一个布局很好地动画化,但第二个布局在开始动画之前有某种闪烁。

当我尝试从第一个布局更改为第三个布局时,它运行良好且流畅。

如果我从第一个变为第二个(有眨眼),然后从第二个变为第三个 - 它工作得很好,即使我从第三个回到第二个 - 它工作得很好。

就像它第一次加载第二个布局时一样 - 它必须在动画之前闪烁,但是当它已经创建时 - 它的动画进出平滑..

有任何想法吗 ?

4

2 回答 2

0

我在片段交易中遇到过类似的问题。我使用了向左滑动、向右滑动的动画,当这种情况发生时,屏幕顶部会出现故障。我最初认为它与 ActionBar 有关,因为那是发生故障的地方。

经过进一步审查,解决方案是将 SurfaceView 的背景设置为透明,如下所示:

android:background="@android:color/transparent"

感谢Asaf Nevo 和Riasat引导我找到这个解决方案。

于 2014-10-28T00:20:49.000 回答
0

我实际上发现了问题:VideoView导致延迟..可能是因为我没有在其中设置任何视频..无论如何,我删除了它,现在效果很好!:)

于 2013-10-26T11:36:12.870 回答