我有一个布局,如果我按下这个布局,另一个线性布局将来自右侧(动画),它将在其上预览,但如果我点击布局2,Onclicklistener将不起作用,
但是如果将我的第一个布局可见性设置为Gone,那么将在layout2上调用这些操作,
我使用layout2.bringToFront();
移动布局顶部,但操作仍无效
这是我的完整源代码
public class MainActivity extends Activity implements OnClickListener {
ImageView btnHover;
LinearLayout layout1, layout2;
boolean isPageOpen = false;
Animation translateLeftAnim;
Animation translateRightAnim;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_sample);
btnHover = (ImageView) findViewById(R.id.contact_row_icon);
layout1 = (LinearLayout) findViewById(R.id.cell_view);
layout2 = (LinearLayout) findViewById(R.id.cell_option_view);
layout1.setOnClickListener(this);
layout2.setOnClickListener(this);
btnHover.setOnClickListener(this);
translateLeftAnim = AnimationUtils.loadAnimation(this,
R.anim.slide_left);
translateRightAnim = AnimationUtils.loadAnimation(this,
R.anim.slide_right);
SlidingPageAnimationListener animListener = new SlidingPageAnimationListener();
translateLeftAnim.setAnimationListener(animListener);
translateRightAnim.setAnimationListener(animListener);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v == layout1) {
layout2.setVisibility(View.VISIBLE);
slideToLeft(layout2);
layout2.bringToFront();
} else if (v == btnHover) {
layout1.setVisibility(View.VISIBLE);
slideToRight(layout2);
}else if (v==layout2){
Log.d("tag", "clicked");
}
}
private class SlidingPageAnimationListener implements AnimationListener {
public void onAnimationEnd(Animation animation) {
if (isPageOpen) {
layout2.setVisibility(View.INVISIBLE);
isPageOpen = false;
} else {
isPageOpen = true;
}
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
}
// To animate view slide out from left to right
public void slideToRight(View view) {
TranslateAnimation animate = new TranslateAnimation(
layout1.getWidth(), 0, 0, 0);
animate.setDuration(500);
animate.setFillAfter(true);
view.startAnimation(animate);
layout2.setVisibility(View.INVISIBLE);
}
// To animate view slide out from right to left
public void slideToLeft(View view) {
TranslateAnimation animate = new TranslateAnimation(0,
-layout1.getWidth(), 0, 0);
animate.setDuration(500);
animate.setFillAfter(true);
view.startAnimation(animate);
}
}