【问题标题】:Getting error in CardView when i use Parent Left and right当我使用 Parent Left 和 Right 时 CardView 出现错误
【发布时间】:2016-02-11 08:15:17
【问题描述】:

我是 android 新手,在 CardView 中出现错误,日志如下所示

错误日志

Error:(14) No resource identifier found for attribute 'align_parentRight' in package 'android'

Error:(27) No resource identifier found for attribute 'align_parentLeft' in package 'android'

Error:(27) No resource identifier found for attribute 'align_toLeftOf' in package 'android'

请任何人帮助我如何解决这个问题,我在谷歌搜索但我的问题没有解决,请不要帮助我

这是我的 XML 代码

    <android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    xmlns:card_view="http://schemas.android.com/tools"

    android:layout_margin="8dp"
    card_view:cardElevation="5dp"
    card_view:cardCornerRadius="5dp">
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/image_view"
            android:layout_width="120dp"
            android:layout_height="170dp"
            android:src="@drawable/imag_bg"
            android:align_parentRight="true"
            android:layout_marginTop="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginEnd="20dp"
            android:layout_centerVertical="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />


<TextView

    android:layout_width="180dp"
    android:layout_height="wrap_content"
    android:text="TextView"
    android:textColor="#FF00FF"
    android:textSize="22dp"
    android:textStyle="bold"
    android:layout_marginLeft="20dp"
       android:align_parentLeft="true"
        android:align_toLeftOf="@+id/image_view"
    android:id="@+id/text_View"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="20dp" />

    </RelativeLayout>
</android.support.v7.widget.CardView>

【问题讨论】:

  • 请更改代码以了解您的问题
  • 我不确定这是否正确,但请尝试仅使用 android:layout_alignParentRight
  • 我改变我的代码看看@FabioVenturiPastor
  • 张贴你想要或清楚的截图
  • 我发布了我的帖子,我发布了我想要的图片,请看@AmitVaghela

标签: android xml android-layout android-studio android-cardview


【解决方案1】:

根据您的屏幕截图检查此答案

<?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.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/nameDetailsBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/saveDeleteBar"
        android:layout_margin="10dip">

        <LinearLayout
            android:id="@+id/relativeLayout4"
            style="@style/Widget.CardContent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:weightSum="4">

                <LinearLayout
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="3.25"
                    android:orientation="vertical"
                    android:weightSum="3">

                    <TextView
                        android:id="@+id/textview1"
                        android:layout_width="match_parent"
                        android:layout_height="0dip"
                        android:layout_weight="1"
                        android:ellipsize="end"
                        android:gravity="left|center_vertical"
                        android:padding="5dp"
                        android:singleLine="true"
                        android:text="1"
                        android:textColor="@color/darkslate"
                        android:textSize="@dimen/font_normal_size"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/textview2"
                        android:layout_width="match_parent"
                        android:layout_height="0dip"
                        android:layout_weight="1"
                        android:ellipsize="end"
                        android:gravity="left|center_vertical"
                        android:padding="5dp"
                        android:singleLine="true"
                        android:text="2"
                        android:textColor="@color/darkslate"
                        android:textSize="@dimen/font_normal_size_small"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/textview3"
                        android:layout_width="match_parent"
                        android:layout_height="0dip"
                        android:layout_weight="1"
                        android:ellipsize="end"
                        android:gravity="left|center_vertical"
                        android:padding="5dp"
                        android:singleLine="true"
                        android:text="3"
                        android:textColor="@color/darkslate"
                        android:textSize="@dimen/font_normal_size"
                        android:textStyle="bold" />
                </LinearLayout>

                <ImageView
                    android:id="@+id/imgDoctorPresentation"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right|center_vertical"
                    android:layout_weight="0.75"
                    android:adjustViewBounds="true"
                    android:padding="5dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/presentation" />
            </LinearLayout>
        </LinearLayout>
    </android.support.v7.widget.CardView>


</LinearLayout>

【讨论】:

  • 无法解析符号 style="@style/Widget.CardContent"@Amit Vaghela
  • 它是风格,现在不需要那种风格
  • 你有解决办法吗@chanti
  • 在我的图像中,我需要顶部和结束空间,如屏幕上方短@Amit Vaghela
  • 将 android:layout_marginTop="10dp" android:layout_marginBottom="10dp" 添加到 ImageView @chanti
【解决方案2】:

请删除 xml 属性 align_parentLeftalign_parentRightalign_toLeftOf,因为这是未知属性

另外请进一步解释您希望布局是什么样子,您的代码似乎令人困惑,您使用了太多的 alignParent 属性。

【讨论】:

    【解决方案3】:

    您正在使用 align_parentLeftalign_parentRightalign_toLeftOf 。这些是无效的 xml 属性。你的工作代码在这里。

    <android.support.v7.widget.CardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        xmlns:card_view="http://schemas.android.com/tools"
    
        android:layout_margin="8dp"
        card_view:cardElevation="5dp"
        card_view:cardCornerRadius="5dp">
        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <ImageView
                android:id="@+id/image_view"
                android:layout_width="120dp"
                android:layout_height="170dp"
                android:src="@drawable/imag_bg"
                android:layout_marginTop="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginEnd="20dp"
                android:layout_centerVertical="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true" />
    
    
            <TextView
    
                android:layout_width="180dp"
                android:layout_height="wrap_content"
                android:text="TextView"
                android:textColor="#FF00FF"
                android:textSize="22dp"
                android:textStyle="bold"
                android:layout_marginLeft="20dp"
                android:layout_toLeftOf="@+id/image_view"
                android:id="@+id/text_View"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_marginTop="20dp" />
    
        </RelativeLayout>
    </android.support.v7.widget.CardView>
    

    干杯...继续编码

    【讨论】:

      【解决方案4】:

      您也可以通过使用线性布局和使用权重来实现这一点,并为您的布局使用相对布局,除了 imageView 下面是示例

      <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:card_view="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="200dp"
      
          android:layout_margin="8dp"
          card_view:cardCornerRadius="5dp"
          card_view:cardElevation="5dp">
      
          <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:weightSum="3">
      
              <RelativeLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_weight="2">
      
      
                  <TextView
      
                      android:id="@+id/text_View"
                      android:layout_width="180dp"
                      android:layout_height="wrap_content"
                      android:layout_alignParentLeft="true"
                      android:layout_alignParentStart="true"
                      android:layout_alignParentTop="true"
                      android:layout_marginLeft="20dp"
                      android:layout_marginTop="20dp"
                      android:text="TextView"
                      android:textColor="#FF00FF"
                      android:textSize="22dp"
                      android:textStyle="bold" />
      
              </RelativeLayout>
      
              <ImageView
                  android:id="@+id/image_view"
                  android:layout_width="120dp"
                  android:layout_height="170dp"
                  android:src="@drawable/imag_bg"
                  android:layout_marginEnd="20dp"
                  android:layout_marginRight="20dp"
                  android:layout_marginTop="20dp"
                  android:layout_weight="1" />
          </LinearLayout>
      </android.support.v7.widget.CardView>
      

      【讨论】:

        猜你喜欢
        • 2019-01-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-09-16
        • 2012-12-04
        • 1970-01-01
        相关资源
        最近更新 更多