3

When I use the ScrollView some of the columns got fit. Example: enter image description here

DNI column should be a little wider. The reason of using scrollview is because I will add more columns. I tried to change "match_parent" and some trick from other post of StackOverflow, but I don't get any successful result.

I refactored the code in order to avoid nested weight and use "0dp":

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.privacity.PermisosActivity"
tools:ignore="MergeRootFrame" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/gray"
    android:orientation="vertical"
    android:weightSum="1" >

    <HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:baselineAligned="false"
            android:weightSum="2" >

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1" >

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignTop="true" >

                    <CheckBox
                        android:id="@+id/chkNombre"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_above="@+id/textView3"
                        android:layout_alignTop="true"
                        android:layout_gravity="center"
                        android:background="@xml/nombre_checkbox"
                        android:button="@null" />

                    <TextView
                        android:id="@+id/textView3"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:layout_alignParentLeft="true"
                        android:layout_gravity="center"
                        android:text="@string/nombre"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textSize="15sp" />
                </RelativeLayout>

               <!-- ANOTHER RelativeLayout -->
            </RelativeLayout>
            <!-- FIN DE COLUMNA -->

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1" >

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignTop="true" >

                    <CheckBox
                        android:id="@+id/chkDNI"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_above="@+id/textView4"
                        android:layout_alignTop="true"
                        android:background="@xml/dni_checkbox"
                        android:button="@null" />

                    <TextView
                        android:id="@+id/textView4"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:layout_alignParentLeft="true"
                        android:gravity="center"
                        android:text="@string/nombre"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textSize="15sp" />
                </RelativeLayout>

                <!-- ANOTHER RelativeLayout -->
            </RelativeLayout>
            <!-- FIN COLUMNA -->

        </LinearLayout>
    </HorizontalScrollView>

    <Button
        android:id="@+id/AceptarPerfil"
        style="@style/btnStyleGreen"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="5dp"
        android:layout_weight="0.5"
        android:onClick="validar"
        android:text="@string/validar" />
</LinearLayout>

</FrameLayout>

If I change the text (Nombre instead of DNI), the widths are the same, so something wrong happens with my textview or their parents.

enter image description here

I would like to know why this happens.

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
ecorzo
  • 605
  • 1
  • 6
  • 7
  • Which is the size you want to scale in percent (only one)? this one must be set to **0dp**, not `match_parent` or `wrap_content`! – Phantômaxx Jul 17 '14 at 16:23
  • I tried to put layout_width="0dp" in each column and I got the same result . – ecorzo Jul 17 '14 at 16:34
  • Well, your beloved weightSum is optional, since Android calculates it by itself. `android:layout_weight="0dp"` is the only way to let Android know **WHICH** is the dimension you want to scale in percentage. Remember you can scale only one at a time: width or height. If you want to scale bothe, you have to use **NESTED weights**, which is **BAD for performances**. – Phantômaxx Jul 17 '14 at 16:37
  • I just discovered that if I change the text "DNI" by "Nombre", the columns have the same size but I don't know why the texts have the property to change the size of the LinearLayout (columns) – ecorzo Jul 17 '14 at 16:43
  • I forgot to mention that weights go with the appropriate `android:orientation` attribute: http://developer.android.com/guide/topics/ui/layout/linear.html – Phantômaxx Jul 17 '14 at 18:03
  • @FrankN.Stein I followed your comments, but I'm still getting the same problem. I edited the topic. – ecorzo Jul 17 '14 at 18:46
  • I think the problem resides in the **overcomplicate layout nesting**. Try simplifying as much as you can by removing useless (really!) "containers of containers". – Phantômaxx Jul 17 '14 at 19:01
  • @FrankN.Stein, I did it , but it doesn't solve the problem. – ecorzo Jul 18 '14 at 07:42
  • Simplify more. Remove as many layouts as possible. Reengineer your design to be **S I M P L E** – Phantômaxx Jul 18 '14 at 08:21

0 Answers0