尺寸会自动增加 这是我的代码 当我第一次点击任何菜单时,尺寸增加然后一切都很好 我希望当点击任何按钮时图标会改变,而不会在棒棒糖之前改变android中按钮的大小
fab = (FloatingActionButton)findViewById(R.id.fab);
fab1 = (FloatingActionButton)findViewById(R.id.fab1);
fab2 = (FloatingActionButton)findViewById(R.id.fab2);
fab_open = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fab_open);
fab_close = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fab_close);
rotate_forward = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.rotate_forward);
rotate_backward = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.rotate_backward);
fab.setOnClickListener(this);
fab1.setOnClickListener(this);
fab2.setOnClickListener(this);
}
@Override
public void onClick(View v) {
int id = v.getId();
switch (id){
case R.id.fab:
animateFAB();
break;
case R.id.fab1:
toggle();
Log.d("Raj", "Fab 1");
break;
case R.id.fab2:
Log.d("Raj", "Fab 2");
break;
}
}
private void toggle() {
if(isopen) {
isopen=false;
fab1.setImageResource(R.drawable.ic_3d_rotation_black_18dp);
}else {
isopen=true;
fab1.setImageResource(R.drawable.ic_3d_rotation_white_18dp);
}
}
public void animateFAB(){
if(isFabOpen){
fab.startAnimation(rotate_backward);
fab1.startAnimation(fab_close);
fab2.startAnimation(fab_close);
fab1.setClickable(false);
fab2.setClickable(false);
isFabOpen = false;
Log.d("Raj", "close");
} else {
fab.startAnimation(rotate_forward);
fab1.startAnimation(fab_open);
fab2.startAnimation(fab_open);
fab1.setClickable(true);
fab2.setClickable(true);
isFabOpen = true;
Log.d("Raj", "open");
}
}
}
答案 0 :(得分:0)
在执行fab.setImageResource()
之前,请执行以下操作:
fab.setScaleType(ImageView.ScaleType.CENTER_CROP);