0

For some reason the layouts "lefttop" and "topright" remain at 0dp in my fragment.

I have checked that when I give an actual value (id: 50dp) to the width of either relative layout the items within it actually begin appearing.I also made sure that the parent relativelayout of "lefttop" and "topright" actually does actually take up the whole width and height of my cardview.

Is there something wrong with the way that I implemented the weightSum and layout_weight? I looked at many different similar issues that people had

This is my code:

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    card_view:cardCornerRadius="4dp"
    android:layout_margin="5dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum = "1.5">

        <!--Top Left section (name and adress)-->
        <RelativeLayout
            android:id="@+id/lefttop"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight = "1"
            android:background="@drawable/borderright">

            <TextView
                android:id="@+id/title"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:text="contact det"
                android:gravity="center_vertical"
                android:textColor="@android:color/black"
                android:paddingLeft="5dp"
                android:textSize="40dp"
                android:layout_alignParentTop="true"/>

            <TextView
                android:id="@+id/txtName"
                android:layout_width="wrap_content"
                android:layout_height="10dp"
                android:text="Name"
                android:gravity="center_vertical"
                android:textSize="10dp"
                android:layout_below="@id/title"
                android:layout_marginTop="10dp"
                android:layout_marginLeft="0dp"
                android:paddingLeft="15dp"/>
        </RelativeLayout>


        <!--top right section with type of job and company-->
       <RelativeLayout
        android:id="@+id/topright"
        android:layout_toRightOf="@+id/lefttop"
        android:layout_width="0dp"
        android:layout_height="26dp"
        android:layout_weight = "0.5"
        android:background="@drawable/borderright">


               <TextView
                   android:id="@+id/txtSurname"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:text="Surname"
                   android:gravity="center_vertical"
                   android:textSize="10dp"
                   android:layout_alignParentTop="true"
                   android:layout_marginTop="10dp"
                   android:layout_marginLeft="5dp"
                   android:background="@drawable/borderdown"/>

           <TextView
               android:id="@+id/txtEmail"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="Email"
               android:textSize="10dp"
               android:layout_marginTop="10dp"
               android:layout_marginLeft="5dp"/>

           </RelativeLayout>




    </RelativeLayout>
    </android.support.v7.widget.CardView>
JJ Jetson
  • 5
  • 3
  • 1
    `layout_weight` is only applicable to `View`s inside a `LinearLayout`. Yours are in a `RelativeLayout`. – Mike M. Oct 22 '16 at 05:15
  • 1
    That did the trick! Odd that it compiled without any errors though. Thanks for the prompt reply Mike! – JJ Jetson Oct 22 '16 at 05:20

1 Answers1

2

layout_weight is only Applicable in LinearLayout..... here is your solution......

 <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

    card_view:cardCornerRadius="4dp"
    android:layout_margin="5dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum = "1.5">

        <!--Top Left section (name and adress)-->
        <LinearLayout
            android:id="@+id/lefttop"
            android:layout_width="50dp"
            android:layout_height="0dp"
            android:layout_weight = "1"
            android:background="@drawable/borderright">

            <TextView
                android:id="@+id/title"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:text="contact det"
                android:gravity="center_vertical"
                android:textColor="@android:color/black"
                android:paddingLeft="5dp"
                android:textSize="40dp"
                android:layout_alignParentTop="true"/>

            <TextView
                android:id="@+id/txtName"
                android:layout_width="wrap_content"
                android:layout_height="10dp"
                android:text="Name"
                android:gravity="center_vertical"
                android:textSize="10dp"
                android:layout_below="@id/title"
                android:layout_marginTop="10dp"
                android:layout_marginLeft="0dp"
                android:paddingLeft="15dp"/>
        </LinearLayout>


        <!--top right section with type of job and company-->
       <LinearLayout
        android:id="@+id/topright"
        android:layout_toRightOf="@+id/lefttop"
        android:layout_width="26dp"
        android:layout_height="0dp"
        android:layout_weight = "0.5"
        android:background="@drawable/borderright">


            <TextView
                android:id="@+id/txtSurname"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Surname"
                android:gravity="center_vertical"
                android:textSize="10dp"
                android:layout_alignParentTop="true"
                android:layout_marginTop="10dp"
                android:layout_marginLeft="5dp"
                android:background="@drawable/borderdown"/>

           <TextView
               android:id="@+id/txtEmail"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="Email"
               android:textSize="10dp"
               android:layout_marginTop="10dp"
               android:layout_marginLeft="5dp"/>

           </LinearLayout>

    </LinearLayout>
    </android.support.v7.widget.CardView>
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198