Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Did I get that right - you just want to have some blue view containing a white view that shows up when the blue view is clicked?</p> <p>Then it would be better not to implement your own <code>ViewGroup</code> but using one of the existing ones like <code>FrameLayout</code>. Set the layout's background to blue. Add a child <code>View</code> with it's background set to white and it's visibility set to <code>View.INVISIBLE</code> or <code>View.GONE</code>.</p> <p>Add a click handler to the <code>ViewGroup</code> that sets the visibility of your white <code>View</code> to <code>View.VISIBLE</code>.</p> <p>You could do it like this:</p> <p>main.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="#00f" android:onClick="onBlueClick" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;View android:id="@+id/whiteBox" android:background="#fff" android:visibility="gone" android:layout_gravity="center" android:layout_width="20dp" android:layout_height="20dp"/&gt; &lt;/FrameLayout&gt; </code></pre> <p>MyActivity.java:</p> <pre><code>package com.example; import android.app.Activity; import android.os.Bundle; import android.view.View; public class MyActivity extends Activity { private View whiteBox; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); whiteBox = findViewById(R.id.whiteBox); } @SuppressWarnings({"UnusedDeclaration"}) // wired by layout xml public void onBlueClick(final View view) { if (whiteBox != null) { whiteBox.setVisibility(whiteBox.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE); } } } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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