import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.dk.view.folder.ResideMenu;
public class HomeFragment extends Fragment {
private View parentView;
private ResideMenu resideMenu;
ImageView imagef;
public Animation objani;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
parentView = inflater.inflate(R.layout.home, container, false);
setUpViews();
try {
RelativeLayout r1=(RelativeLayout)inflater.inflate(R.layout.home, container, false);
ImageView imagef = (ImageView) r1.findViewById(R.id.imageViewu);
objani = AnimationUtils.loadAnimation(getActivity(),
R.anim.asd);
imagef.startAnimation(objani);
}
catch(Exception ae)
{
Toast.makeText(getActivity(),ae.getMessage(),Toast.LENGTH_LONG).show();
}
return parentView;
}
private void setUpViews() {
MenuActivity parentActivity = (MenuActivity) getActivity();
resideMenu = parentActivity.getResideMenu();
parentView.findViewById(R.id.btn_open_menu).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
resideMenu.openMenu(ResideMenu.DIRECTION_RIGHT);
}
});
}
}
}
进入淡入(动画),但我的程序不起作用
#这里是home.xml的xml代码,它是homefragment.java的xml代码..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:orientation="vertical"
android:id="@+id/r1">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:gravity="center"
android:orientation="vertical"
android:weightSum="1"
android:id="@+id/l1">
<ImageView
android:layout_width="190dp"
android:layout_height="wrap_content"
android:id="@+id/imageViewu"
android:src="@drawable/gesture"
android:layout_gravity="center_horizontal" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="false"
android:padding="5dp"
android:text=" 1. Swipe right/left to open menu"
android:textColor="#ffacacac"
android:textSize="17sp" />
<Button
android:id="@+id/btn_open_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:background="@drawable/button_selector"
android:padding="12dp"
android:text="Play!!!"
android:textColor="@android:color/white"
android:textSize="17sp" />
</LinearLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<alpha
android:duration="1000"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
</set>