在启动我的应用程序时,我想要一个类似于图像幻灯片的闪屏。通过向左或向右滑动,您可以简要了解应用程序的功能。在每个图像底部的某处,我想修复一个菜单,如项目,以显示图像的导航。它可以简单地是一个实心圆链,告诉用户他们所处的图像。
任何人告诉我这种闪屏的术语是什么,我该怎么做?
由于
答案 0 :(得分:2)
我想你想在Splashscreen中显示多个图像。在下面的活动中,它有一个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>
答案 1 :(得分:-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,就像tat一样。 添加一个到z 26图像,或根据条件使用你需要的方式改变位置。 我在这里使用了26张图片,在第25位,我打算进行下一次活动。这个wat你问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>