gpt4 book ai didi

android - 如何在 Android 上显示启动画面 3 秒?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:06:02 25 4
gpt4 key购买 nike

我希望初始图像开始并停留 3 秒,然后消失并继续或被 main.xml 中的其余布局替换。

这是我的代码:

主.java

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);

ImageView splash = (ImageView) this.findViewById(R.id.splash);

主.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- margin=0px, padding=20px -->
<!--textview padding=10dp, textSize=16sp-->
<!--px=pixel, dp=density indepen sp=scale indepen fontsize preference -->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ImageView
android:id="@+id/splash"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/splash2"/>

<ImageView
android:id="@+id/myImageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bg_main"/>

<ImageView
android:id="@+id/myImageView0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bar_top"/>

<!--
<TextView android:id="@+id/textItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="10dp"
android:paddingLeft="110dp"
android:background="#00000000"
android:textColor="#ffffffff"
android:textSize="22sp"
android:text="Find Car"
android:enabled="false"
>
-->

<TabHost android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3dp">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom = "@android:id/tabcontent"
/>
</RelativeLayout>
</TabHost>
</RelativeLayout>

最佳答案

你可以这样做

ImageView splash = (ImageView) this.findViewById(R.id.splash);

splash.postDelayed(new Runnable(){
splash.setVisibility(View.GONE);
}, 3000);

或者可以通过调用此方法(来自 Android 文档)而不是直接将可见性设置为 GONE 来添加动画

private void fadeSplashOut() {
// Set the content view to 0% opacity but visible, so that it is visible
// (but fully transparent) during the animation.
mContentView.setAlpha(0f);
mContentView.setVisibility(View.VISIBLE);

// Animate the content view to 100% opacity, and clear any animation
// listener set on the view.
mContentView.animate()
.alpha(1f)
.setDuration(mShortAnimationDuration)
.setListener(null);

// Animate the loading view to 0% opacity. After the animation ends,
// set its visibility to GONE as an optimization step (it won't
// participate in layout passes, etc.)
splash.animate()
.alpha(0f)
.setDuration(mShortAnimationDuration)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
splash.setVisibility(View.GONE);
}
});
}

关于android - 如何在 Android 上显示启动画面 3 秒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8958459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com