Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在eclipse中创建自动滑动图像的背景_Javascript_Android_Css_Eclipse - Fatal编程技术网

Javascript 如何在eclipse中创建自动滑动图像的背景

Javascript 如何在eclipse中创建自动滑动图像的背景,javascript,android,css,eclipse,Javascript,Android,Css,Eclipse,我是Eclipse和Android开发的新手。我正在开发一个应用程序,希望在我的启动屏幕后出现的第一个屏幕有一个由图片组成的背景,以幻灯片的形式显示,每张图片之间间隔5秒。我不知道如何解决这个问题,我非常感谢每一个有用的材料,可以指导我完成这项工作。指望你的好主意。我还需要知道图片应该采用哪种格式,以及它们是否都必须具有相同的尺寸。 谢谢 编辑代码包括在内 package com.joel.mybusapp; import android.support.v7.app.ActionBarAct

我是Eclipse和Android开发的新手。我正在开发一个应用程序,希望在我的启动屏幕后出现的第一个屏幕有一个由图片组成的背景,以幻灯片的形式显示,每张图片之间间隔5秒。我不知道如何解决这个问题,我非常感谢每一个有用的材料,可以指导我完成这项工作。指望你的好主意。我还需要知道图片应该采用哪种格式,以及它们是否都必须具有相同的尺寸。 谢谢

编辑代码包括在内

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>
<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:gravity="bottom"
    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>


</RelativeLayout>

我用ViewFLipper和ImageView工具实现了背景的自动滑动。上面的代码只适用于屏幕周围有一个白色的边界,我想让它消失。我确实做了每一个容器来装满你的父母,但白人寄宿生仍然存在。下面是我的意思的屏幕截图。我需要一些帮助来摆脱白人寄宿生。

使用可视翻转器。您需要添加带有所需位图的ImageView,然后开始翻转视图。图像应该是res/drawables dir、PNG或JPEG格式的,当然它们会作为位图加载。它们不需要大小相同,可以使用ImageView的SCALE TYPE属性来调整它们的外观。

下面的代码修复了问题中解决的所有问题,这要感谢@Frederick nyawaya的想法

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>
<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:gravity="bottom"
    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>


</RelativeLayout>

请给我们看看你到目前为止的代码。只需使用他们目前使用的格式。不要害怕犯错误。您可以在以后对最终结果进行优化。@Stephanbraczyk,谢谢。到目前为止,我已经用代码更新了问题。你的图像在哪里?@Stephanbraczyk谢谢。我的图片在res/drawables hdpi文件夹中谢谢。我不知道这个概念是如何运作的,所以我有点困惑。我必须为每张图片交替添加ImageView和viewflipper吗?还是先添加所有ImageView,然后添加一个viewflipper来翻转视图?谢谢@fredrick。我不知道这个概念是如何运作的,所以我有点困惑。我是否必须为每张图片交替添加ImageView和viewflipper,还是先添加所有ImageView,然后添加一个viewflipper来翻转视图?。此外,我还必须设置viewFLipper的哪些值,以便在从右到左每5秒自动发生一次转换,并在页面/视图启动一次转换loads@fredrick我需要在哪里添加异常以避免我的应用程序崩溃?