简体   繁体   English

如何使按钮在Onclick事件上显示和消失

[英]How to make buttons to appear and disappear on the Onclick event

我有2个按钮邀请和共享,如果我单击邀请,则会出现包含4个imageviews的linearlayout bar1,对于共享按钮,在这4个imageview选项中也将显示相同的linearlayout bar2,如果我单击邀请和共享按钮,则布局栏均会出现,但是对我来说,当我单击“邀请”或共享时,一次只能显示一个对应的栏...

if I understand you correctly something like this will do the trick: 如果我对您的理解正确,则可以使用以下方法:

invite.setOnClickListener(new OnClickListener(){
    public void onClick(View v){
        linearlayoutbar1.setVisibility(View.VISIBLE);
        linearlayoutbar2.setVisibility(View.GONE);
    }
});

share.setOnClickListener(new OnClickListener(){
    public void onClick(View v){
        linearlayoutbar2.setVisibility(View.VISIBLE);
        linearlayoutbar1.setVisibility(View.GONE);
    }
});

Insert LinearyLayout upon your requirements 根据您的要求插入LinearyLayout

<merge>
<LinearLayout
    android:id="@+id/main"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:visibility="gone"  
    />
<LinearLayout
    android:id="@+id/sub"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:visibility="gone"  
    />  
</merge>

depending upon your invite and share button you can put these code invite.setOnClickListener() or share.setOnClickListener()

Insert Visibility of LinearLayout according to your Logic 根据您的逻辑插入LinearLayout的可见性

LinearLayout mainLayout=(LinearLayout)this.findViewById(R.id.main);
LinearLayout subLayout=(LinearLayout)this.findViewById(R.id.sub);

invite.setOnClickListener(new OnClickListener()
{
   public void onClick(View v)
    {
    mainLayout.setVisibility(View.VISIBLE);        
    }
});

 share.setOnClickListener(new OnClickListener()
 {
   public void onClick(View v)
    {
    subLayout.setVisibility(View.VISIBLE);        
    }
 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM