如何制作类似图片幻灯片的启动画面

5
在我的应用程序启动时,我想要一个类似于图像幻灯片的启动画面。通过左右滑动,您可以简要地查看应用程序的功能。在每个图像的底部的某个地方,我想要固定一个菜单项,以显示图像的导航。它可以是一系列实心圆圈,告诉用户他们正在查看哪张图片。
请问这种启动画面的术语是什么?我该如何做到这一点?
谢谢

在应用程序启动期间添加一个简单的“活动”,并在此“活动”中执行您想要的操作,关于“xml”视图。 - Abhijit Muke
我能把它们全部聚合到一个SplashActivity中吗?为每个图像做一个似乎有些过度设计了。 - Daniel
@Daniel,你可以使用SplashActivity来完成这个任务。 - Abhijit Muke
2
你需要使用ViewPager,如果它能满足你的需求,请查看此库 - Mehul Joisar
看一下这个,希望它能够工作... https://dev59.com/72855IYBdhLWcg3wy3oc - Farhan Shah
2个回答

2

我认为您想在启动界面中显示多个图像。在下面的活动中,有一个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张图片,它们会在特定的时间间隔内显示。
<?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>

我觉得这个可以!谢谢。你能帮我看一下这个吗?http://stackoverflow.com/questions/20857721/how-to-draw-a-line-of-circles-in-android - Daniel
使用 GitHub 中的示例代码,如果出现任何错误,请发布。 - AruLNadhaN
1
不,我不想使用ViewPagerIndicator。能否通过使用标准库来解决? - Daniel
@AruLNadhaN 我遇到了 "animation-list 未定义" 的错误.. 有任何想法吗? - Ranjithkumar

-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个图像,或者根据需要使用多少个来更改位置if条件。 我在这里使用了26个图像,在第25个位置上我打算跳转到下一个活动。这是你要求的对吧? 如果您得到了您想要的,请接受答案,如果有任何疑问,请更新我。
不要忘记将两个活动添加到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>

你能告诉我哪个语句可以嵌入多张图片吗?一个启动画面应该包含许多可以左右滑动的图片。 - Daniel
启动画面是在应用程序启动时显示图像的功能。多个图像意味着什么?您指定了什么? - kathir
接受我的答案,如果你需要什么请告诉我。祝编码愉快,伙计 :) - kathir
就像你在底部有一个表格一样,你可以通过图片滑动,当你滑动到最后一张图片时,你将进入主活动。 - Daniel
除了这里的选项菜单,还有什么其他的? - Daniel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接