首页 > 如何在Fragment中添加SurfaceView,像墨迹天气的动态背景

如何在Fragment中添加SurfaceView,像墨迹天气的动态背景

我想在我的程序中植入墨迹天气那种动态背景,
使用activity的setContentView运行动态背景没问题:
public class SnowActivity extends Activity {
SnowSurfaceView snowSurfaceView;

@Override
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    Log.i("icer", "-->onCreate(");
    snowSurfaceView = new SnowSurfaceView(this);
    setContentView(snowSurfaceView);
}

问题是如何在Fragment中让这种动态背景效果运行起来,保持原布局不变,通过获取到的天气状态判断来显示具体出什么动态背景效果,让该效果像在activity一样,在该Fragment的布局上单独运行。
public class ZeroFragment extends Fragment implements OnClickListener {

SnowSurfaceView snowSurfaceView;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_zero, container, false);

    wearTextView = (TextView) view.findViewById(R.id.zero_wear);
    weatherTextView = (TextView) view.findViewById(R.id.zero_weather);

    getckWeather getckweather = new getckWeather();
    getckweather.execute();//去获取天气数据,天气数据存到myGlobal这个application里
    loadAnimation();// 根据获取到的天气判断打开相应背景动画
    return view;
}

private void loadAnimation() {

    if (myGlobal.weather.equals("晴")) {
        Toast.makeText(getActivity(), "开始动画", Toast.LENGTH_SHORT).show();
        snowSurfaceView = new SnowSurfaceView(getActivity());//在这之后该加什么代码??
    }
}
【热门文章】
【热门文章】