RadiodButton切换Fragment,切换图片帧动画显示

图片绑定的一定要是动画的布局,bt_ok1

Activity代码


public class MainActivityextends AppCompatActivityimplements View.OnClickListener {

private FrameLayoutmFrame;

private RadioButtonbut1;

private RadioButtonbut2;

private RadioButtonbut3;

private RadioButtonbut4;

private RadioButtonlive;

@Override

    protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

initView();

}

private void initView() {

mFrame = (FrameLayout) findViewById(R.id.fragment);

mFrame.setOnClickListener(this);

//        mLinear = (LinearLayout) findViewById(R.id.mLinear);

//        mLinear.setOnClickListener(this);

        but1 = (RadioButton) findViewById(R.id.but1);

but1.setOnClickListener(this);

but2 = (RadioButton) findViewById(R.id.but2);

but2.setOnClickListener(this);

but3 = (RadioButton) findViewById(R.id.but3);

but3.setOnClickListener(this);

but4 = (RadioButton) findViewById(R.id.but4);

but4.setOnClickListener(this);

live = (RadioButton) findViewById(R.id.live);

live.setOnClickListener(this);

}

private void initFragment(Fragment fragment) {

FragmentManager supportFragmentManager = getSupportFragmentManager();

FragmentTransaction transaction = supportFragmentManager.beginTransaction();

transaction.replace(R.id.fragment, fragment);

transaction.commit();

}

@Override

    public void onClick(View v) {

switch (v.getId()) {

case R.id.but1:

AFragment aFragment =new AFragment();

initFragment(aFragment);

break;

case R.id.but2:

BFragment bFragment =new BFragment();

initFragment(bFragment);

break;

case R.id.but3:

CFragment cFragment =new CFragment();

initFragment(cFragment);

break;

case R.id.but4:

DFragment dFragment =new DFragment();

initFragment(dFragment);

break;

case R.id.live:

TaskFragment taskFragment =new TaskFragment();

initFragment(taskFragment);

break;

}

}

}


二:在drawable中创建动画

    先把图片加入到mipmap  


起的动画名      bt_ok1


报错,直接生成文件



再建一个XML,才是真正的显示动画

你可能感兴趣的:(RadiodButton切换Fragment,切换图片帧动画显示)