title: View fill space if sibling is gone
body: <p>So, I'm trying to get a <code>TextView</code> to fill the space left by a <code>ImageView</code> when it is <code>GONE</code>... I've tried using <code>LinearLayout</code> and <code>RelativeLayout</code>, but the ImageView's space isn't taken by the TextView.</p>
  
  <p>So, how I get it to work?</p>
  
  <p>Code:</p>
  
  <pre><code>&lt;RelativeLayout
      android:orientation="horizontal"
      android:id="@+id/cabecalho"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;ImageView
          android:layout_width="30dp"
          android:layout_height="30dp"
          android:layout_alignParentLeft="true"
          android:layout_centerVertical="true"
          android:id="@+id/imgPrimary"
          android:visibility="gone"
          android:src="@drawable/abc_btn_rating_star_on_mtrl_alpha"
          android:tint="#ecac31"
          android:layout_gravity="center_vertical"
          android:padding="3dp" /&gt;
  
      &lt;TextView
          android:layout_width="match_parent"
          android:layout_height="17dp"
          android:text="Endereço de Teste"
          android:layout_toRightOf="@+id/imgPrimary"
          android:layout_toLeftOf="@+id/btnEdit"
          android:layout_centerVertical="true"
          android:id="@+id/addrTitle"
          android:layout_weight="50"
          android:textColor="@color/black"
          android:layout_gravity="center_vertical"
          android:layout_marginLeft="5dp" /&gt;
  
      &lt;ImageButton
          android:layout_width="40dp"
          android:layout_height="40dp"
          android:id="@+id/btnEdit"
          android:layout_weight="1"
          android:layout_toLeftOf="@+id/btnDelete"
          android:src="@drawable/icon_write_location"
          android:tint="#08b8ae"
          android:scaleType="fitCenter"
          android:background="@color/white"
          android:padding="10dp" /&gt;
  
      &lt;ImageButton
          android:layout_width="40dp"
          android:layout_height="40dp"
          android:id="@+id/btnDelete"
          android:layout_weight="1"
          android:scaleType="fitXY"
          android:src="@drawable/abc_ic_clear_mtrl_alpha"
          android:tint="#d60d0d"
          android:layout_alignParentRight="true"
          android:background="@color/white"
          android:padding="7dp" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Requested print:
  <a href="https://i.stack.imgur.com/0P9VL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0P9VL.png" alt="The space is to the right of the bold &quot;Teste&quot; at the top of the white card."></a>
  The space is to the right of the bold "Teste" at the top of the white card.</p>
  
  <p>Code from my recyclerview adapter:</p>
  
  <pre><code>public class AddrAdapter extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt; {
      private List&lt;Address&gt; addressList;
  
      public class ViewHolder extends RecyclerView.ViewHolder {
          public LinearLayout layout;
  
          public TextView titulo, enderecoCompleto;
          public ImageButton btnEdit, btnDelete;
          public ImageView isDefaultStar;
          //public RelativeLayout cabecalho;
  
          public ViewHolder(LinearLayout layout) {
              super(layout);
              this.layout = layout;
  
              this.titulo = (TextView) layout.findViewById(R.id.addrTitle);
              this.enderecoCompleto = (TextView) layout.findViewById(R.id.addrComplete);
              this.btnEdit = (ImageButton) layout.findViewById(R.id.btnEdit);
              this.btnDelete = (ImageButton) layout.findViewById(R.id.btnDelete);
              this.isDefaultStar = (ImageView) layout.findViewById(R.id.imgPrimary);
              //this.cabecalho = (RelativeLayout) layout.findViewById(R.id.cabecalho);
          }
      }
  
      public class ViewHolderHint extends RecyclerView.ViewHolder {
          public TextView text;
  
          public ViewHolderHint(TextView text) {
              super(text);
              this.text = text;
          }
      }
  
      public AddrAdapter(List&lt;Address&gt; addresses) {
          this.addressList = addresses;
          if (addresses.size() &gt; 0 &amp;&amp; this.addressList.get(0).getCity() != null) {
              this.addressList.add(0, new Address());
          }
      }
  
      @Override
      public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          switch (viewType) {
              case 0 : {
                  TextView v = (TextView) LayoutInflater.from(parent.getContext())
                          .inflate(R.layout.card_address_hint, parent, false);
  
                  ViewHolderHint vhh = new ViewHolderHint(v);
                  return vhh;
              }
              default : {
                  LinearLayout v = (LinearLayout) LayoutInflater.from(parent.getContext())
                          .inflate(R.layout.card_address, parent, false);
  
                  ViewHolder vh = new ViewHolder(v);
                  return vh;
              }
          }
      }
  
      @SuppressLint("SetTextI18n")
      @Override
      public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
          if (position &lt; 1) {
              ViewHolderHint hint = (ViewHolderHint) holder;
              hint.text.setText(Html.fromHtml("Selecione um &lt;b&gt;endereço de entrega&lt;/b&gt;"));
          } else {
              final ViewHolder layout = (ViewHolder) holder;
  
              layout.isDefaultStar.setVisibility((addressList.get(position).getDefaultAddress()) ? View.VISIBLE : View.GONE);
              //layout.cabecalho.requestLayout();
              layout.titulo.setText(addressList.get(position).getTitle());
              layout.enderecoCompleto.setText(
                      addressList.get(position).getDescription()+", "+
                              addressList.get(position).getNumber()+"\n"+
                              addressList.get(position).getComplement()+", "+
                              addressList.get(position).getNeighborhood()+" - "+
                              addressList.get(position).getCity().getName()+" - "+
                              addressList.get(position).getCity().getState().getCode()+"\n"+
                              addressList.get(position).getZipcode()
              );
  
              layout.btnEdit.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      int pos = layout.getAdapterPosition();
                      Address addr = addressList.get(pos);
  
                      Bundle b = new Bundle();
                      b.putSerializable("ADDRESS_TO_EDIT",addr);
                      b.putInt("CHAVE_ENDERECO",pos); // TODO: Talvez no futuro seja a ID do endereço
                      Intent i = new Intent(AddressActivity.this,CheckoutAddressAddEditActivity.class);
                      i.putExtras(b);
                      startActivityForResult(i,006);
                  }
              });
  
              layout.btnDelete.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      int pos = layout.getAdapterPosition();
  
                      addresses.remove(pos);
  
                      notifyItemRemoved(pos);
                  }
              });
  
              layout.layout.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      int pos = layout.getAdapterPosition();
                      Address addr = addressList.get(pos);
  
                      Bundle extras = new Bundle();
                      extras.putSerializable("ADDRESS", addr);
                      Intent data = new Intent();
                      data.putExtras(extras);
                      setResult(RESULT_OK, data);
                      finish();
                  }
              });
          }
      }
  
      @Override
      public int getItemCount() {
          return addresses.size();
      }
  
      @Override
      public int getItemViewType(int pos) {
          return (pos &gt; 0) ? 1 : 0;
      }
  }
  </code></pre>