Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I fail to understand the purpose of doing things this way. Wouldn't it be simpler to create a RelativeLayout with a TextView on top of an ImageView? Something like:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="128dp" android:layout_marginTop="51dp" android:src="@android:drawable/btn_dialog" /&gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/imageView1" android:layout_alignTop="@+id/imageView1" android:layout_centerHorizontal="true" android:text="TextView" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Or even better, place the TextView in a LinearLayout, and set the image to the LinearLayout's background?</p> <p>Edit, reply to comment:</p> <p>It's not about being efficient, it's about trying to put a square peg in a round hole. It basically seems as if you're setting a single object - the custom ImageView - as the entire layout, then attempting to add additional elements to the single object (the TextView). Attempting to do is exactly what the Layout objects are for: containing a collection of other objects. In this case, ImageViews and TextViews.</p> <p>Of course, I might have missed the purpose here. If it's an exercise in unusual ways of doing things, then I understand. However, if you're just attempting to get things on the screen, it seems like a very complicated way of doing that. Typically, the command <code>setContentView(R.layout.activity_main);</code> sets an XML file with the root object being some version of a Layout object (LinearLayout, RelativeLayout, etc.) Within that layout would be the objects you want to manipulate. Perhaps we don't have the entirety of your MainActivity.xml? </p>
    singulars
    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.
 

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