使按钮隐藏5秒钟

时间:2018-04-01 06:46:10

标签: android android-animation android-button

目标:
当您启动该应用时, 该按钮应在5秒后显示。

  

顺便说一下,启动应用 - >隐藏按钮 - >等待5秒 - >显示按钮

问题:
代码不起作用,我错过了哪个部分?

的信息:
*我是新的Android,这是我尝试

return  min([[dis(p,q),p,q] for p in points[:len(points)-1] for q in points[1:] if p!=q])

任何帮助将不胜感激

xml androidmanifest

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Button button2 = (Button) findViewById(R.id.btn_test);
        button2.setVisibility(GONE);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try{
                    //dummy delay for 5 second
                    Thread.sleep(5000);
                }
                catch (InterruptedException e){
                    e.printStackTrace();
                }
                runOnUiThread(new Runnable() { //resetting the visibility of the button
                    @Override
                    public void run() {

                        //manipulating UI components from outside of the UI Thread require a call to runOnUiThread
                        button2.setVisibility(VISIBLE);
                    }
                });
            }
        }).start();
    }
}

activity_main xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.jfdimarzio.labb3">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

3 个答案:

答案 0 :(得分:2)

好像你错过了<groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-server</artifactId> <version>3.11.0</version> ..先解决这个问题..

setContentView

请勿使用setContentView(R.layout.main_activity); Thread。请改用sleep ..

handler post delayed

答案 1 :(得分:0)

如此简单,您无需动作动画即可动画。只需设置持续时间,在结束动画后,监听器将显示它

&#13;
&#13;
buttonvVew.setVisibility(View.GONE);

buttonView.animate()
      .setDuration(5000)
      .setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
          super.onAnimationEnd(animation);
          buttonView.setVisibility(View.visible);
        }
});
&#13;
&#13;
&#13;

答案 2 :(得分:0)

试试这个

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main.xml);
        Button button2 = (Button) findViewById(R.id.btn_test);
        button2.setVisibility(GONE);
        button2.postDelayed(new Runnable() {
            public void run() {
                button2.setVisibility(View.VISIBLE);
            }
        }, 5000);
    }
}