Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my relative layout filling the screen rather than wrapping content when I add an image?
    primarykey
    data
    text
    <p>I have a RelativeLayout, we'll call this the 'slider', that I want to overlay on another RelativeLayout (by switching visibility="gone" and "visible") when "Add People" is clicked, but the overlay should only take up as much width of the screen as needed. This layout will then be removed when "Cancel" is clicked. Everything is working fine so far.</p> <p><img src="https://i.stack.imgur.com/eKHC2.png" alt="correct_closed"> <img src="https://i.stack.imgur.com/wFjYA.png" alt="correct_open"></p> <pre><code>RelativeLayout slider; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_people); RelativeLayout add = (RelativeLayout) findViewById(R.id.add_wrapper); RelativeLayout cancel = (RelativeLayout) findViewById(R.id.cancel_wrapper); slider = (RelativeLayout) findViewById(R.id.add_people_slider); add.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { slider.setVisibility(View.VISIBLE); } }); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { slider.setVisibility(View.GONE); } }); } </code></pre> <p>The issue arises when I try to add another image to the slider. I am adding this just above the @id/cancel_wrapper RelativeLayout in the XML (full XML at bottom).</p> <pre><code>&lt;ImageView android:id="@+id/transparent_add" android:src="@drawable/ic_add_active_256" android:layout_height="30dp" android:layout_width="30dp" android:layout_alignParentTop="true" android:layout_alignParentRight="true" /&gt; </code></pre> <p><img src="https://i.stack.imgur.com/fa1G3.png" alt="bad"></p> <p>For some reason, this is making the width of the slider the full width of the screen.</p> <p>What's even more bizarre is if I add <code>android:layout_marginRight="50dp"</code> to this ImageView to move it left a little it starts making the slider smaller from the left. I would like this "transparent_add" image to be lined up with the old "add" image.</p> <p><img src="https://i.stack.imgur.com/W2Vxu.png" alt="bad with margin"></p> <p>My 2 issues, then, are that when I add the "transparent_add" image it changes the width of the slider for an unknown reason, and also when I add marginRight on the image it makes the width of the slider smaller from the left.</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="fill_parent" android:layout_height="fill_parent" android:background="@color/white" &gt; &lt;TextView android:id="@+id/btn_people" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:paddingLeft="10dp" android:text="@string/label_people" android:textColor="@color/blue" android:textSize="16dp" /&gt; &lt;TextView android:id="@+id/people_info" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/btn_people" android:paddingLeft="10dp" android:text="@string/label_people_info" android:textSize="11dp" /&gt; &lt;RelativeLayout android:id="@+id/add_wrapper" android:layout_width="65dp" android:layout_height="50dp" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:background="@color/blue" &gt; &lt;ImageView android:id="@+id/plus_sign" android:layout_width="25dp" android:layout_height="25dp" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginRight="19dp" android:layout_marginTop="6dp" android:src="@drawable/ic_add_256" /&gt; &lt;TextView android:id="@+id/add_people" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:paddingBottom="2dp" android:text="@string/label_add_people" android:textColor="@color/white" android:textSize="11dp" /&gt; &lt;/RelativeLayout&gt; &lt;ListView android:id="@+id/contacts_list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentLeft="true" android:layout_below="@id/people_info" /&gt; &lt;!-- switch between visible/gone --&gt; &lt;RelativeLayout android:id="@+id/add_people_slider" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentRight="true" android:background="@color/blue" android:visibility="gone" &gt; &lt;TextView android:id="@+id/label_add_new_contact" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="65dp" android:layout_alignParentTop="true" android:paddingLeft="10dp" android:paddingRight="15dp" android:text="@string/label_add_new_contact" android:textColor="@color/white" android:textSize="16dp" /&gt; &lt;TextView android:id="@+id/label_add_from_phone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/label_add_new_contact" android:paddingLeft="10dp" android:paddingRight="15dp" android:paddingTop="15dp" android:text="@string/label_add_from_phone" android:textColor="@color/white" android:textSize="16dp" /&gt; &lt;TextView android:id="@+id/label_add_from_facebook" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/label_add_from_phone" android:paddingLeft="10dp" android:paddingRight="15dp" android:paddingTop="15dp" android:text="@string/label_add_from_facebook" android:textColor="@color/white" android:textSize="16dp" /&gt; &lt;TextView android:id="@+id/label_add_from_linkedin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/label_add_from_facebook" android:paddingLeft="10dp" android:paddingRight="15dp" android:paddingTop="15dp" android:text="@string/label_add_from_linkedin" android:textColor="@color/white" android:textSize="16dp" /&gt; &lt;!-- insert image here --&gt; &lt;RelativeLayout android:id="@+id/cancel_wrapper" android:layout_width="wrap_content" android:layout_height="50dp" android:paddingLeft="15dp" android:paddingRight="15dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:paddingBottom="10dp" &gt; &lt;ImageView android:id="@+id/image_cancel" android:layout_width="25dp" android:layout_height="25dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="4dp" android:src="@drawable/ic_close_256"/&gt; &lt;TextView android:id="@+id/label_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:text="@string/label_cancel" android:textColor="@color/white" android:textSize="8dp" /&gt; &lt;/RelativeLayout&gt; &lt;/RelativeLayout&gt; &lt;/RelativeLayout&gt; </code></pre> <p>EDIT: This is happening both in Eclipse and on my Android device.</p> <p>EDIT: I have tried placing the image above the "Add a new contact" text and then placing the text below that, but the same thing happens</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.
 

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