【问题标题】:How to make a splash screen like image slide如何制作像图像幻灯片一样的启动画面
【发布时间】:2013-12-31 11:01:26
【问题描述】:

在我的应用程序启动时,我想要一个类似于图像幻灯片的启动画面。通过向左或向右滑动,您可以简要了解应用程序的功能。在每张图片底部的某处,我想修复一个类似项目的菜单以显示图片的导航。它可以简单地是一串实心圆圈,告诉用户他们在哪个图像。

有人告诉我这种启动画面的术语是什么,我该怎么做?

谢谢

【问题讨论】:

  • 在启动应用程序期间的特定时间添加一个简单的activity。并在此activityxml 视图中做你想做的事情..
  • 我可以将它们全部聚合到一个 SplashActivity 中吗?为每张图片做一个似乎有点过头了
  • @Daniel..确保你可以使用SplashActivity..
  • 你需要使用ViewPager。看看this library是否满足您的要求。
  • 看看这个,希望它成功了..stackoverflow.com/questions/4139288/…

标签: android splash-screen


【解决方案1】:

我想你想在 Splashscreen 中显示多个图像。在下面的 Activity 中,它有一个 ImageView 显示多个图像,并且图像可以以不同的时间间隔显示。

Splash.java

public class Splash extends Activity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_splash);
            final ImageView splashImageView = (ImageView) findViewById(R.id.SplashImageView);
            splashImageView.setBackgroundResource(R.anim.splash);
            final AnimationDrawable frameAnimation = (AnimationDrawable)splashImageView.getBackground(); 
                            Thread timer= new Thread(){
                                                        public void run(){
                    try{
                                    sleep(7000);
                    }catch(InterruptedException e){
                    e.printStackTrace();
                }finally {
                    Intent splash =new Intent("com.arul.remoteit.Main");
                    startActivity(splash);
                }
                }
            };
        timer.start();
            splashImageView.post(new Runnable(){
                @Override
                public void run() {
                    frameAnimation.start();    
                               }            
            });
                }
    @Override
            protected void onPause() {
                // TODO Auto-generated method stub
                super.onPause();
                finish();
            }

        }

在这个 XML 文件中,您必须指定必须显示的图像。这里我有 5 个图像,它们以特定的时间间隔显示。

splash.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/flaganim"
    android:oneshot="false"
    >
    <item android:drawable="@drawable/s1" android:duration="1000" />
    <item android:drawable="@drawable/s2" android:duration="1000" />
    <item android:drawable="@drawable/s3" android:duration="1000" />
     <item android:drawable="@drawable/s4" android:duration="1000" />
    <item android:drawable="@drawable/s5" android:duration="1000" />
    </animation-list>

【讨论】:

  • 我认为这行得通!谢谢。你也可以帮我看看这个吗?stackoverflow.com/questions/20857721/…
  • 如果您有任何错误,请使用 GitHub 中的示例代码并发布。
  • 不,我不想使用 ViewPagerIndicator。使用标准库可以解决吗?
  • @AruLNadhaN 动画列表未定义错误我得到了.. 任何想法?
【解决方案2】:

只需创建一个带有图像作为背景的 xml 文件,如下所示。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageSwitcher android:id="@+id/switcher"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
    />

    <Gallery android:id="@+id/gallery"
        android:background="#55000000"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"

        android:gravity="center_vertical"
        android:spacing="16dp"
    />

</RelativeLayout>

对于这个活动:

public class MainActivity extends Activity implements
        AdapterView.OnItemSelectedListener, ViewSwitcher.ViewFactory {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.activity_main);

        mSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
        mSwitcher.setFactory(this);
        mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
                android.R.anim.fade_in));
        mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
                android.R.anim.fade_out));

        Gallery g = (Gallery) findViewById(R.id.gallery);
        g.setAdapter(new ImageAdapter(this));
        g.setOnItemSelectedListener(this);
    }

    public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
        mSwitcher.setImageResource(mImageIds[position]);
    }

    public void onNothingSelected(AdapterView<?> parent) {
    }

    public View makeView() {
        ImageView i = new ImageView(this);
        i.setBackgroundColor(0xFF000000);
        i.setScaleType(ImageView.ScaleType.FIT_CENTER);
        i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT));
        return i;
    }

    private ImageSwitcher mSwitcher;

    public class ImageAdapter extends BaseAdapter {
        public ImageAdapter(Context c) {
            mContext = c;
        }

        public int getCount() {
            return mThumbIds.length;
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView i = new ImageView(mContext);

            i.setImageResource(mThumbIds[position]);


            if(position==25)
            {

                Intent intent = new Intent(MainActivity.this, NextActivity.class);
                startActivity(intent);
        finish();

            }


            i.setAdjustViewBounds(true);
            i.setLayoutParams(new Gallery.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            i.setBackgroundResource(R.drawable.a);
            return i;
        }

        private Context mContext;

    }

    private Integer[] mThumbIds = {
            R.drawable.a, R.drawable.b, R.drawable.c,
            R.drawable.d, R.drawable.e, R.drawable.f,
            R.drawable.g, R.drawable.h, R.drawable.i,
            R.drawable.j, R.drawable.k, R.drawable.l,
            R.drawable.m, R.drawable.n, R.drawable.o,
            R.drawable.p, R.drawable.q, R.drawable.r,
            R.drawable.s, R.drawable.t, R.drawable.u,
            R.drawable.v, R.drawable.w, R.drawable.x,
            R.drawable.y, R.drawable.z
            };

    private Integer[] mImageIds = {
            R.drawable.a, R.drawable.b, R.drawable.c,
            R.drawable.d, R.drawable.e, R.drawable.f,
            R.drawable.g, R.drawable.h, R.drawable.i,
            R.drawable.j, R.drawable.k, R.drawable.l,
            R.drawable.m, R.drawable.n, R.drawable.o,
            R.drawable.p, R.drawable.q, R.drawable.r,
            R.drawable.s, R.drawable.t, R.drawable.u,
            R.drawable.v, R.drawable.w, R.drawable.x,
            R.drawable.y, R.drawable.z
            };

}

在这段代码中,我打算从 MainActivity 到 NextActivity ,就像现在一样。 添加 a 到 z 26 图像,或根据条件更改位置使用您需要的程度。 我在此使用了 26 张图片,在位置 25 我打算进行下一个活动。这是你问 ryt 的吗? 如果您有需要,请接受答案,如有任何疑问,请告诉我。

不要忘记将两个活动添加到 mainfest。 并且主要认为您需要首先指定启动活动,如下所示。

 <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".splash"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" />




    </application>

【讨论】:

  • 你能告诉我哪个语句有助于嵌入多个图像吗?一个启动画面应该包含许多可以左右滑动的图像
  • 启动画面是在应用程序启动时显示图像。多张图片的意思,你指定吗?
  • 接受我的答案,你想要的,然后告诉我你有你需要的。快乐的编码伙计:)
  • 就像你在底部有一个表格一样,你可以按图片滑动,当你滑动最后一张图片时,你会进入主活动
  • 除了这里的选项菜单是什么
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-27
  • 1970-01-01
  • 2012-09-13
  • 2011-07-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多