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

时间:2013-01-05 10:53:18

标签: java android layout

我有2个按钮邀请和分享,如果我点击邀请linearlayout bar1将出现其中包含4个图像视图,并且对于共享按钮也同样linearlayout bar2在4个imageview选项中,如果我点击邀请和分享按钮两个布局栏出现,但对我来说,当我点击邀请或分享时,一次只能出现一个相应的栏...

2 个答案:

答案 0 :(得分:0)

如果我理解正确的话就会有这样的伎俩:

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);
    }
});

答案 1 :(得分:0)

根据您的要求插入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()

根据您的逻辑插入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);        
    }
 });