如何以编程方式隐藏在Android SDK中的一个按钮按钮、方式、Android、SDK

2023-09-12 22:44:27 作者:先生眼里没我

我有一个包含两个按钮的相对布局。其重叠在彼此

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:后台=#FFFFFF>


<按钮的android:文本=播放
    机器人:ID =@ + ID /播放
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真正的>
< /按钮>

<按钮的android:文本=停止
    机器人:ID =@ + ID /停止
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真正的>
< /按钮>


< / RelativeLayout的>
 

我想以编程方式在同一时间只显示一个按钮,当它的单击事件被调用。 我尝试着用:

  

playButton.setVisibility(1);

但它不worked.Following是一个例子正是我试图做的。

 为playButton =(按钮)findViewById(R.id.play);
    playButton.setVisibility(1);
    playButton.setOnClickListener(新OnClickListener(){
    @覆盖
    公共无效的onClick(视图v){
             //播放时点击显示停止按钮,隐藏播放按钮

        }
    });
 

解决方案 Android shareSDK

您可以使用下面的code

 为playButton =(按钮)findViewById(R.id.play);
    playButton.setVisibility(1);
    playButton.setOnClickListener(新OnClickListener(){
    @覆盖
    公共无效的onClick(视图v){
             //播放时点击显示停止按钮,隐藏播放按钮
             playButton.setVisibility(View.GONE);
             stopButton.setVisibility(View.VISIBLE);

        }
    });
 

I have a relative layout which contains two buttons. Which are overlapped on each other.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF">


<Button android:text="Play"  
    android:id="@+id/play"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom = "true">
</Button>

<Button android:text="Stop "
    android:id="@+id/stop" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_alignParentBottom = "true">
</Button>


</RelativeLayout>

I want to to programmatically show only one button at a time when its click event is called. I tried it with :

playButton.setVisibility(1);

but it does not worked.Following is an example what i am trying to do.

    playButton = (Button) findViewById(R.id.play);
    playButton.setVisibility(1);
    playButton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
             //when play is clicked show stop button and hide play button

        }
    });

解决方案

You can use the following code

playButton = (Button) findViewById(R.id.play);
    playButton.setVisibility(1);
    playButton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
             //when play is clicked show stop button and hide play button
             playButton.setVisibility(View.GONE);
             stopButton.setVisibility(View.VISIBLE);

        }
    });