Guest User

Untitled

a guest
Sep 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. Use Custom View In XML Layout
  2. public class Loading extends View {
  3.  
  4. private long movieStart;
  5. private Movie movie;
  6.  
  7. public Loading(Context context, InputStream inputStream) {
  8. super(context);
  9. movie = Movie.decodeStream(inputStream);
  10. }
  11.  
  12. @Override
  13. protected void onDraw(Canvas canvas) {
  14. canvas.drawColor(Color.WHITE);
  15. super.onDraw(canvas);
  16. final long now = SystemClock.uptimeMillis();
  17. if(movieStart == 0)
  18. movieStart = now;
  19. final int relTime = (int)((now - movieStart) % movie.duration());
  20. movie.setTime(relTime);
  21. movie.draw(canvas, 0, 0);
  22. this.invalidate();
  23. }
  24.  
  25. }
  26.  
  27. How can I use this view in XML layout?
  28.  
  29. <pacakge_of_class.Loading
  30. android:id="@+id/y_view1"
  31. android:layout_width="fill_parent"
  32. android:layout_height="fill_parent" />
  33.  
  34. How can I pass the parameters
  35.  
  36. <view class="Your_package.MainClass$Loading" />
  37.  
  38. <Your-Package-Name.Loading
  39. android:layout_width="fill_parent"
  40. android:layout_height="fill_parent"
  41. />
  42.  
  43. <com.your.package.Loading
  44. android:id="@+id/y_view1"
  45. ... />
  46.  
  47. Loading yourView = (Loading) findViewById(R.id.yourLoadingView);
  48. yourView.setInputStream();
  49.  
  50. public void setInputStream(InputStream inputStream){
  51. movie = Movie.decodeStream(inputStream);
  52. }
Add Comment
Please, Sign In to add comment