Note that there are some explanatory texts on larger screens.

plurals
  1. POInconsistent results using XML layout and SurfaceView
    primarykey
    data
    text
    <p>I'm using an XML layout to show a custom class which extends SurfaceView along with a single button to the right of it, using the XML code below:</p> <p><strong>main.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"&gt; &lt;com.my.name.MySurfaceView android:id="@+id/camera_view" android:layout_width="wrap_content" android:layout_height="wrap_content"/&gt; &lt;Button android:id="@+id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/button_text"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>I'm then using the following code to set the layout for my activity:</p> <p><strong>MyActivity.java</strong></p> <pre><code>public class MyActivity extends Activity { private MySurfaceView mySurfaceView; private Button button; public MyActivity() { } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mySurfaceView = (MySurfaceView) findViewById(R.id.camera_view); button = (Button) findViewById(R.id.button); button.setOnClickListener(new android.view.View.OnClickListener() { public void onClick(View v) { mySurfaceView.setClick(true); } }); } } </code></pre> <p>The <code>MySurfaceView</code> class then extends <code>SurfaceView</code> and is setup to show the camera stream.</p> <p>The problem is, when starting the app, there are often different outcomes. Either:</p> <p>Both the <code>Button</code> and <code>MySurfaceView</code> are drawn to the screen at the same time, then the camera stream starts displaying (This is how I'd like it to work every time)</p> <p><em>or</em></p> <p><code>MySurfaceView</code> loads and shows the camera stream for a few seconds, before the <code>Button</code> is eventually displayed.</p> <p>I understand that the <code>SurfaceView</code> has to be created and measured etc before the button can be displayed so I should expect a slight delay, but as mentioned above, in some cases the <code>SurfaceView</code> displays the camera stream for up to 5 seconds before the button is eventually drawn to the screen.</p> <p>How I can avoid this?</p> <p>Thanks for your help in advance.</p> <p><strong>EDIT:</strong> <br><br> It seems as though the <code>SurfaceView</code> is not completely finished being created, despite being shown on the screen. I'm using OpenCV to process the camera stream and this seems to still be initialising things after the <code>SurfaceView</code> is initially drawn, and so the <code>Button</code> is not drawn until all of this is finished.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload