在我的应用程序启动时,我想要一个类似于图像幻灯片的启动画面。通过左右滑动,您可以简要地查看应用程序的功能。在每个图像的底部的某个地方,我想要固定一个菜单项,以显示图像的导航。它可以是一系列实心圆圈,告诉用户他们正在查看哪张图片。
请问这种启动画面的术语是什么?我该如何做到这一点?
谢谢
请问这种启动画面的术语是什么?我该如何做到这一点?
谢谢
我认为您想在启动界面中显示多个图像。在下面的活动中,有一个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 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>
只需创建一个带有图像背景的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
};
}
<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>
SplashActivity
来完成这个任务。 - Abhijit MukeViewPager
,如果它能满足你的需求,请查看此库。 - Mehul Joisar