我是Eclipse和Android開發的新手。我正在開發一個應用程序,並且希望在我的啓動畫面具有由圖片組成的背景並以每張圖片之間具有5秒的幻燈片形式顯示後顯示的第一個屏幕。我不知道如何解決這個問題,並會感謝每一個有用的材料,可以指導我完成這件事。依靠你的創意。我還需要知道圖片應該放入哪種格式,以及它們是否必須具有相同的尺寸。 謝謝。我如何在eclipse中創建自動滑動圖像的背景
使用代碼進行編輯。
package com.joel.mybusapp;
import android.support.v7.app.ActionBarActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;
public class MainActivity extends ActionBarActivity {
Animation slide_in_left, slide_out_right;
ViewFlipper viewFlipper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewFlipper = (ViewFlipper) this.findViewById(R.id.bckgrndViewFlipper1);
slide_in_left = AnimationUtils.loadAnimation(this,
android.R.anim.slide_in_left);
slide_out_right = AnimationUtils.loadAnimation(this,
android.R.anim.slide_out_right);
viewFlipper.setInAnimation(slide_in_left);
viewFlipper.setOutAnimation(slide_out_right);
//sets auto flipping
viewFlipper.setAutoStart(true);
viewFlipper.setFlipInterval(5000);
viewFlipper.startFlipping();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.joel.mybusapp.MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<ViewFlipper
android:id="@+id/bckgrndViewFlipper1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/bckgrndImageView5"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/bkscreen6"
android:scaleType="centerCrop"
android:src="@drawable/backscreen6png" />
<ImageView
android:id="@+id/bckgrndImageView4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/bkscreen5"
android:scaleType="centerCrop"
android:src="@drawable/backscreen5png" />
<ImageView
android:id="@+id/bckgrndImageView3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/bkscreen3"
android:scaleType="centerCrop"
android:src="@drawable/backscreen3png" />
<ImageView
android:id="@+id/bckgrndImageView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/bkscreen2"
android:scaleType="centerCrop"
android:src="@drawable/backscreen2png" />
<ImageView
android:id="@+id/bckgrndImageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/bkscreen1"
android:scaleType="centerCrop"
android:src="@drawable/backscreen1png" />
</ViewFlipper>
</LinearLayout>
我設法後臺自動帶ViewFLipper和ImageView的工具滑動。上面的代碼的作品只是顯示屏幕周圍有一個白色寄宿生,我想消失。我已經逐字地將每個容器填充爲空,但白色寄宿生物仍然存在。我的意思是屏幕截圖如下。我需要一些幫助擺脫白人邊境。
請告訴我們您的代碼迄今爲止。只需使用他們目前正在使用的格式即可。不要害怕犯錯誤。您以後可以始終優化最終結果。 – 2014-10-19 18:19:35
@StephanBranczyk謝謝。迄今爲止,我已經用代碼更新了這個問題。 – Selase 2014-10-19 18:38:09
你的形象在哪裏? – 2014-10-19 19:01:52