2014-12-10 3 views
0

나는 안드로이드 개발을 처음 접했고, 나는 스플래시 스크린을 구현하고있는 벽지 앱을 만들고있다.스플래시 화면을 좌우로 움직이는 방법 (안드로이드)

스플래시 화면이 표시되는 동안 왼쪽/오른쪽/왼쪽 - 왼쪽으로 이동하고 싶습니다. 참고 : 이미지를 바꾸거나 슬라이딩하는 것이 아니라 이미지를 이동하고 싶습니다. http://www.dailymotion.com/video/x2c8j8e_scr-20141210-183228_school

내가 시작 화면을 이동하는 방법을 모른다 :

그것이 내가 원하는 것을 설명 동영상 아래에있는이를 참조하십시오. 그래서 제발 도와주세요. 난 당신이 배경 화면 이미지를로드 한 다음 자동 스크롤 할 말은 생각

import java.util.ArrayList; 
import java.util.List; 
import java.util.Random; 

import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 

import android.annotation.SuppressLint; 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.Window; 
import android.widget.ImageView; 
import android.widget.Toast; 

import com.android.volley.Request.Method; 
import com.android.volley.Response; 
import com.android.volley.VolleyError; 
import com.android.volley.toolbox.JsonObjectRequest; 
import com.usd.amazingwallpapershd.R; 
import com.usd.amazingwallpapershd.app.AppConst; 
import com.usd.amazingwallpapershd.app.AppController; 
import com.usd.amazingwallpapershd.picasa.model.Category; 

@SuppressLint("NewApi") 
public class SplashActivity extends Activity { 
    private static final String TAG = SplashActivity.class.getSimpleName(); 
    private static final String TAG_FEED = "feed", TAG_ENTRY = "entry", 
      TAG_GPHOTO_ID = "gphoto$id", TAG_T = "$t", 
      TAG_ALBUM_TITLE = "title"; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     getWindow().requestFeature(Window.FEATURE_ACTION_BAR); 
     getActionBar().hide(); 
     setContentView(R.layout.activity_splash); 

     ////splash images array 
     // Randomise a background 
     int[] yourListOfImages= {R.drawable.splash_1, R.drawable.splash_2, R.drawable.splash_3, R.drawable.splash_4, R.drawable.splash_5, R.drawable.splash_6,R.drawable.splash_7}; 

     Random random = new Random(System.currentTimeMillis()); 
     int posOfImage = random.nextInt(yourListOfImages.length - 1); 

     ImageView imageView= (ImageView) findViewById(R.id.splash_imageview); 
     imageView.setBackgroundResource(yourListOfImages[posOfImage]); 
     //// 

     // Picasa request to get list of albums 
     String url = AppConst.URL_PICASA_ALBUMS 
       .replace("_PICASA_USER_", AppController.getInstance() 
         .getPrefManger().getGoogleUserName()); 

     Log.d(TAG, "Albums request url: " + url); 

     // Preparing volley's json object request 
     JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.GET, url, 
       null, new Response.Listener<JSONObject>() { 

        @Override 
        public void onResponse(JSONObject response) { 
         Log.d(TAG, "Albums Response: " + response.toString()); 
         List<Category> albums = new ArrayList<Category>(); 
         try { 
          // Parsing the json response 
          JSONArray entry = response.getJSONObject(TAG_FEED) 
            .getJSONArray(TAG_ENTRY); 

          // loop through albums nodes and add them to album 
          // list 
          for (int i = 0; i < entry.length(); i++) { 
           JSONObject albumObj = (JSONObject) entry.get(i); 
           // album id 
           String albumId = albumObj.getJSONObject(
             TAG_GPHOTO_ID).getString(TAG_T); 

           // album title 
           String albumTitle = albumObj.getJSONObject(
             TAG_ALBUM_TITLE).getString(TAG_T); 

           Category album = new Category(); 
           album.setId(albumId); 
           album.setTitle(albumTitle); 

           // add album to list 
           albums.add(album); 

           Log.d(TAG, "Album Id: " + albumId 
             + ", Album Title: " + albumTitle); 
          } 

          // Store albums in shared pref 
          AppController.getInstance().getPrefManger() 
            .storeCategories(albums); 

          // String the main activity 
          Intent intent = new Intent(getApplicationContext(), 
            MainActivity.class); 
          startActivity(intent); 
          // closing spalsh activity 
          finish(); 

         } catch (JSONException e) { 
          e.printStackTrace(); 
          Toast.makeText(getApplicationContext(), 
            getString(R.string.msg_unknown_error), 
            Toast.LENGTH_LONG).show(); 
         } 

        } 
       }, new Response.ErrorListener() { 

        @SuppressWarnings("deprecation") 
        @Override 
        public void onErrorResponse(VolleyError error) { 
         Log.e(TAG, "Volley Error: " + error.getMessage()); 

         // show error toast 
         Toast.makeText(getApplicationContext(), 
           getString(R.string.splash_error), 
           Toast.LENGTH_LONG).show(); 

         // Unable to fetch albums 
         // check for existing Albums data in Shared Preferences 
         if (AppController.getInstance().getPrefManger() 
           .getCategories() != null 
           && AppController.getInstance().getPrefManger() 
             .getCategories().size() > 0) { 
          // String the main activity 
          Intent intent = new Intent(getApplicationContext(), 
            MainActivity.class); 
          startActivity(intent); 
          // closing spalsh activity 
          finish(); 
         } else { 
          // Albums data not present in the shared preferences 
          // Launch settings activity, so that user can modify 
          // the settings 

          // Intent i = new Intent(SplashActivity.this, 
          // SettingsActivity.class); 
          // // clear all the activities 
          // i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
          // | Intent.FLAG_ACTIVITY_CLEAR_TASK); 
          // startActivity(i); 

          AlertDialog alertDialog = new AlertDialog.Builder(
            SplashActivity.this).create(); 
          alertDialog 
            .setMessage("Please connect to the internet and try again"); 
          alertDialog.setButton("OK", 
            new DialogInterface.OnClickListener() { 
             public void onClick(
               DialogInterface dialog, 
               int which) { 
              finish(); 
             } 
            }); 
          alertDialog.show(); 

         } 

        } 
       }); 

     // disable the cache for this request, so that it always fetches updated 
     // json 
     jsonObjReq.setShouldCache(false); 

     // Making the request 
     AppController.getInstance().addToRequestQueue(jsonObjReq); 

    } 
} 
+0

편집 된 질문보기 – question

답변

0

:

내 코드입니다. 아직 작성하지 않았다면 WallpaperService까지 확장되는 클래스에 대한 여러 템플릿을 찾을 수 있습니다. 또한 Handler + Runnable이 클래스 내에서 반복적으로 draw을 호출하는 데 사용되는 예제를 볼 수 있습니다. 이는 애니메이션을 제공합니다. 이제 화면 크기보다 넓은 클래스로 생성 된 캔바스의 클립 경계를 만지면됩니다. 예를 들면

Rect fullBoundsRect = c.getClipBounds(); 
fullBoundsRect.inset(-tilew, 0); //make the canvas bounds wider 

등이 해당됩니다.

그런 다음 화면 테두리 (canvas.drawBitmap 사용)보다 큰 비트 맵을 그리고 Matrix 조작을 사용하여 반복적으로 화면 전체에서 이동해야합니다.

큰 비트 맵을 사용하는 경우 메모리를 신중하게 관리해야합니다 (자른 부분으로로드해야 할 수도 있음). drawBitmap 명령을 사용하면 몇 가지 옵션이 제공됩니다. Canvas bounds를 넓히는 데 귀찮음). 그러나 이것은 기본적인 아이디어를 제공합니다.

0

배경을 움직여야합니다. 이미지를 각 방향으로 움직여서 캔버스를 찍고 이미지를 계속 그릴 수 있습니다. 이 블로그 게시물을 참조하십시오.

Animating Background Image

0

는 main.xml에 `

<ImageView 
    android:id="@+id/img_animation" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    android:contentDescription="@null" 
    android:src="@drawable/wal" /> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_centerVertical="true" 
    android:layout_marginLeft="66dp" 
    android:text="Background Text" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:textColor="@android:color/white" /> 

MainActivity.java

`공용 클래스 MainActivity는 활동을 확장 {

public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 

ImageView img_animation = (ImageView) findViewById(R.id.img_animation); 

TranslateAnimation animation = new TranslateAnimation(0.0f, 400.0f, 
    0.0f, 0.0f); 
animation.setDuration(5000); 
animation.setRepeatCount(5); 
// if you want infinite 
// animation.setRepeatCount(Animation.INFINITE); 
animation.setRepeatMode(2); 
animation.setFillAfter(true); 
img_animation.startAnimation(animation); 

} 

}

+0

잘됐지만 이미지 크기가 커지고 있습니다. 이미지 크기에 따라 이동하십시오. 이미지 크기를 벗어나지 마십시오. – question

+0

매개 변수 목록을 변경하십시오. TranslateAnimation (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) –

+0

코드를 이해하지 못했습니다. – question

관련 문제