Android布局\u权重属性不工作

Android布局\u权重属性不工作,android,xml,android-layout-weight,Android,Xml,Android Layout Weight,由于某些原因,“左上”和“右上”布局在我的片段中保持在0dp 我已经检查过,当我给任一相对布局的宽度指定一个实际值(id:50dp)时,其中的项目实际上开始出现。我还确保“lefttop”和“topright”的父相对布局实际上占据了我的cardview的整个宽度和高度 我实现weightSum和layou-weight的方式是否有问题?我看了很多不同的类似问题,人们有 这是我的代码: <android.support.v7.widget.CardView xmlns:card_v

由于某些原因,“左上”和“右上”布局在我的片段中保持在0dp

我已经检查过,当我给任一相对布局的宽度指定一个实际值(id:50dp)时,其中的项目实际上开始出现。我还确保“lefttop”和“topright”的父相对布局实际上占据了我的cardview的整个宽度和高度

我实现weightSum和layou-weight的方式是否有问题?我看了很多不同的类似问题,人们有

这是我的代码:

<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>

布局重量仅适用于线性布局。。。。。 这是你的解决方案

 <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>

布局重量仅适用于线性布局。。。。。 这是你的解决方案

 <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>


layout\u weight
仅适用于
线性布局中的
视图。你的是一个
RelativeLayout
。这就成功了!奇怪的是,它编译时没有任何错误。谢谢你的及时回复,迈克<代码>布局重量
仅适用于
线性布局中的
视图
s。你的是一个
RelativeLayout
。这就成功了!奇怪的是,它编译时没有任何错误。谢谢你的及时回复,迈克!