Android : SurfaceView in Android Wear (API 21)

on Friday, January 30, 2015


I want to use a SurfaceView in an Android Wear project in order to render a parallax background (see attached screenie).


The problem: the SurfaceView disappears after about 1000ms but the car remains so there is a pink car on a black background.


The SurfaceView is added via XML layout definition:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:deviceIds="wear_round"
android:id="@+id/rlMain"
android:background="#FF3333FF"
android:keepScreenOn="true"
>
<com.kiteflo.sniper.BackgroundView
android:id="@+id/backgroundView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:scaleType="centerInside"
/>
</RelativeLayout>


The car is added programmatically:



BackgroundView bgView = (BackgroundView)findViewById(R.id.backgroundView);
RelativeLayout rlMain = (RelativeLayout)findViewById(R.id.rlMain);

// add car
CarView cv = new CarView(selfReference, new Car(0, 0, BitmapFactory.decodeResource(getResources(),
R.drawable.car_pink)), bgView.getBackgroundModel());
rlMain.addView(cv);
...


Did anybody experience the same behavior and maybe found a workaround for this one?


Thanx in advance, Florian


enter image description here


0 comments:

Post a Comment