Android - SurfaceView and layouts

edited February 2014 in Help request
I don't know a lot about how to do UI stuff on Android so apologies if this is very basic. I'd like to create a layout where part of the screen is the SurfaceView (?) where orx is rendered, and another part is an Android UI component (a button).

I've had a brief look at OrxActivity.java and get the impression that this is possible (and maybe even easy) but haven't really had much success getting something working yet...

Should I be using id/orxSurfaceView" as an ID in my layout XML or is there some other way I should go about this?

Comments

  • edited February 2014
    Hi boxjar,

    It's indeed very easy to achieve this.

    In your sub OrxActivity class, call setContentView(R.id.your_layout); to create your Activity layout.

    OrxActivity will detect that a layout has been inflated and will try to find a SurfaceView with the id orxSurfaceView.
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent" android:layout_height="match_parent">
    
        <SurfaceView
            android:id="@+id/orxSurfaceView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:visibility="gone"
            android:layout_gravity="center_horizontal|top"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="@string/banner_id" />
    
    </FrameLayout>
    
  • edited February 2014
    Thanks for that! It makes a lot of sense.

    I've just had some time to play around with this. I more or less copied your layout XML and am doing setContentView(...) in my onCreate method but the screen just renders black without any errors in the log.

    If I comment out setContentView(...) my application renders just as before (but without the layout of course).

    Trying to narrow this down but not sure yet what's wrong. :unsure:
  • edited February 2014
    Hold on! It was just me being stupid - I only had to clean and rebuild the Android OrxLib and now it's working beautifully! Thanks again!
Sign In or Register to comment.