Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Use Custom View In XML Layout
- public class Loading extends View {
- private long movieStart;
- private Movie movie;
- public Loading(Context context, InputStream inputStream) {
- super(context);
- movie = Movie.decodeStream(inputStream);
- }
- @Override
- protected void onDraw(Canvas canvas) {
- canvas.drawColor(Color.WHITE);
- super.onDraw(canvas);
- final long now = SystemClock.uptimeMillis();
- if(movieStart == 0)
- movieStart = now;
- final int relTime = (int)((now - movieStart) % movie.duration());
- movie.setTime(relTime);
- movie.draw(canvas, 0, 0);
- this.invalidate();
- }
- }
- How can I use this view in XML layout?
- <pacakge_of_class.Loading
- android:id="@+id/y_view1"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent" />
- How can I pass the parameters
- <view class="Your_package.MainClass$Loading" />
- <Your-Package-Name.Loading
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- />
- <com.your.package.Loading
- android:id="@+id/y_view1"
- ... />
- Loading yourView = (Loading) findViewById(R.id.yourLoadingView);
- yourView.setInputStream();
- public void setInputStream(InputStream inputStream){
- movie = Movie.decodeStream(inputStream);
- }
Add Comment
Please, Sign In to add comment