0

I am trying to do a row for a recyclerview, row will be splited in 3 columns

  1. First - Image Button
  2. Second- Content (textviews)
  3. Third - Image Button

and when i load a huge content, it make the layout to grow, and its ok, but i want the side panels to grow in height too:

what i want(And Android Studio SHOW that will be (liar =( )):

enter image description here

and what i really got:

enter image description here

and my row.xml is this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

  <RelativeLayout
      android:id="@+id/thebig_father_layout"
      android:layout_width="match_parent"
      android:background="@android:color/holo_blue_bright"
      android:layout_height="match_parent">


      <RelativeLayout
          android:background="@android:color/holo_red_dark"
          android:layout_alignParentLeft="true"
          android:gravity="center_vertical"
          android:id="@+id/i_must_grow_in_height"
          android:layout_width="48dp"
          android:layout_height="match_parent">
          <TextView
              android:text="Grow and to center!!!!"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
      </RelativeLayout>



      <RelativeLayout

          android:background="@android:color/holo_green_dark"
          android:layout_toRightOf="@+id/i_must_grow_in_height"

          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_toLeftOf="@+id/relativeLayout4">

          <LinearLayout
              android:gravity="center_vertical"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

              <TextView
                  android:text="Im the content i can grow in height but the side panels must GROW TOO"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />

              <TextView
                  android:text="Im the content i can grow in height but the side panels must GROW TOO"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />

              <TextView
                  android:text="Im the content i can grow in height but the side panels must GROW TOO"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />

              <TextView
                  android:text="Im the content i can grow in height but the side panels must GROW TOO"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />

              <Button
                  android:text="Random Content"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />
              <Button
                  android:text="Random Content"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />
              <Button
                  android:text="Random Content"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />
              <Button
                  android:text="Random Content"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />
              <Button
                  android:text="Random Content"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />
              <Button
                  android:text="Random Content"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />


          </LinearLayout>
      </RelativeLayout>



      <RelativeLayout
          android:background="@android:color/holo_red_dark"
          android:layout_width="48dp"
          android:gravity="center_vertical"

          android:layout_alignParentRight="true"
          android:layout_height="match_parent"
          android:id="@+id/relativeLayout4">

          <TextView
              android:text="C'mon i need it too"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />

      </RelativeLayout>

  </RelativeLayout>
</RelativeLayout>

someone can explain WHY its not growing(the red Layout) ?

Abhinav singh
  • 1,448
  • 1
  • 14
  • 31
user2582318
  • 1,607
  • 5
  • 29
  • 47

2 Answers2

2

In those layouts where you have used

android:background="@android:color/holo_red_dark"

Make their height auto adjusted according to the content not to the container's height.

android:layout_height="wrap_content"

and if you want image-Buttons to go Red from the beginning then try height of textView inside that red color RelativeLayout as match_parent.

<RelativeLayout
        android:id="@+id/relativeLayout4"
        android:layout_width="48dp"
        android:layout_height="match_parent"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:background="@color/Red"
        android:gravity="center" >

        <TextView
            android:layout_width="wrap_content"
            android:gravity="center"
            android:layout_height="match_parent"
            android:text="C&apos;mon i need it too" />
</RelativeLayout>

Screenshot of my LG OG(4.1.2).

enter image description here Here is full XMl, very minute changes , i think you should clean project and try on other device or emulator...

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<RelativeLayout
    android:id="@+id/thebig_father_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/Blue" >

    <RelativeLayout
        android:id="@+id/i_must_grow_in_height"
        android:layout_width="48dp"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:background="@color/Red"
        android:gravity="center_vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Grow and to center!!!!" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_toEndOf="@+id/i_must_grow_in_height"
        android:layout_toLeftOf="@+id/relativeLayout4"
        android:layout_toRightOf="@+id/i_must_grow_in_height"
        android:layout_toStartOf="@+id/relativeLayout4"
        android:background="@color/Blue" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            android:orientation="vertical" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Im the content i can grow in height but the side panels must GROW TOO" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Im the content i can grow in height but the side panels must GROW TOO" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Im the content i can grow in height but the side panels must GROW TOO" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Im the content i can grow in height but the side panels must GROW TOO" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Random Content" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Random Content" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Random Content" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Random Content" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Random Content" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Random Content" />
        </LinearLayout>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout4"
        android:layout_width="48dp"
        android:layout_height="match_parent"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:background="@color/Red"
        android:gravity="center" >

        <TextView
            android:layout_width="wrap_content"
            android:gravity="center"
            android:layout_height="match_parent"
            android:text="C&apos;mon i need it too" />
    </RelativeLayout>
</RelativeLayout>

mfaisalhyder
  • 2,250
  • 3
  • 28
  • 38
1

The row.xml code you have posted is working for me? check if you have multiple row.xml files in your project under different density etc. (included modules/libraries). One way to check this easily is to hover your pointer above the R.layout.row in your Java code and click while holding Ctrl. This will give all places where this row.xml file exist.

View v = LayoutInflater.from(parent.getContext()) .inflate(R.layout.row, parent, false);

I would suggest using less nested views, and this can be done with a LinearLayout as well:

RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_bright">

<ImageButton
    android:id="@+id/imageButtonOnLeft"
    android:layout_width="48dp"
    android:layout_height="match_parent"

    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"

    android:layout_gravity="center_vertical"
    android:background="@android:color/holo_red_dark"
    android:contentDescription="info button"
    android:src="@android:drawable/ic_dialog_info"
    android:text="Grow and to center!!!!" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_vertical"

    android:layout_toEndOf="@+id/imageButtonOnLeft"
    android:layout_toRightOf="@+id/imageButtonOnLeft"

    android:layout_toLeftOf="@+id/imageButtonOnRight"
    android:layout_toStartOf="@+id/imageButtonOnRight"

    android:background="@android:color/holo_green_dark"
    android:gravity="center_vertical"
    android:orientation="vertical"
    android:padding="8dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Im the content i can grow in height but the side panels must GROW TOO" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Random Content" />

</LinearLayout>

<ImageButton
    android:id="@+id/imageButtonOnRight"
    android:layout_width="48dp"
    android:layout_height="match_parent"

    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"

    android:layout_gravity="center_vertical"
    android:background="@android:color/holo_red_dark"
    android:contentDescription="dialer button"
    android:src="@android:drawable/ic_dialog_dialer"
    android:text="C'mon i need it too" />

</RelativeLayout>

LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_bright"
android:orientation="horizontal">


<ImageButton
    android:id="@+id/imageButtonOnLeft"
    android:layout_width="48dp"
    android:layout_height="match_parent"
    android:layout_gravity="center_vertical"
    android:background="@android:color/holo_red_dark"
    android:contentDescription="info button"
    android:src="@android:drawable/ic_dialog_info"
    android:text="Grow and to center!!!!" />


<LinearLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_gravity="center_vertical"
    android:layout_weight="1"
    android:background="@android:color/holo_green_dark"
    android:gravity="center_vertical"
    android:orientation="vertical"
    android:padding="8dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Im the content i can grow in height but the side panels must GROW TOO" />


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Random Content" />


</LinearLayout>


<ImageButton
    android:id="@+id/imageButtonOnRight"
    android:layout_width="48dp"
    android:layout_height="match_parent"
    android:layout_gravity="center_vertical"
    android:background="@android:color/holo_red_dark"
    android:contentDescription="dialer button"
    android:src="@android:drawable/ic_dialog_dialer"
    android:text="C'mon i need it too" />


 </LinearLayout>
TouchBoarder
  • 6,422
  • 2
  • 52
  • 60
  • awesome thank you, maybe the problem was a lot of nested panels, can you just explain why in LinearLayout ```android:layout_width="0dp" and weigh=1? ``` – user2582318 Nov 12 '15 at 08:03
  • Quoted Lint Warning: "When only a single widget in a LinearLayout defines a weight, it is more efficient to assign a width/height of 0dp to it since it will absorb all the remaining space anyway. With a declared width/height of 0dp it does not have to measure its own size first." check out this answer for more on the weight attr: http://stackoverflow.com/questions/3995825/what-does-androidlayout-weight-mean – TouchBoarder Nov 12 '15 at 08:16