问题描述
|
我有一些奇怪的要求。我有一些菜单按钮。当我单击按钮时,其他三个按钮应该可见。但是,当焦点移到另一个菜单按钮时,这3个按钮应该隐藏或不可见。我做了第一个要求。但是无法做到第二。我采用相对布局中的三个按钮。
<RelativeLayout android:id=\"@+id/relativelayout_inventory\"
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
android:layout_below=\"@id/relativelayout_menu\"
android:layout_toRightOf=\"@id/relativelayout_checkout\"
android:layout_marginTop=\"10px\"
android:layout_marginLeft=\"18px\"
android:visibility=\"invisible\"
>
<Button android:id=\"@+id/stckupdt\"
android:background=\"@drawable/stckupdt\"
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
>
</Button>
<Button android:id=\"@+id/pushoffer\"
android:background=\"@drawable/stckstatus\"
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
android:layout_below=\"@id/stckupdt\"
android:layout_marginTop=\"10px\"
>
</Button>
</RelativeLayout>
在Java文件中,我编写如下代码。
final Button button_inventory = (Button)findViewById(R.id.inventory);
final RelativeLayout view_inventory = (RelativeLayout)findViewById(R.id.relativelayout_inventory);
button_inventory.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
view_inventory.setVisibility(View.VISIBLE);
}
});
解决方法
那么您打算像Windows菜单那样做吗?我不知道为什么需要在手机上进行操作,但是最好将触摸事件看成OnClickListener:处理UI事件