12

我在 CardView 中使用了 LinearLayout 来获得一种社交媒体登录按钮的外观,并且运行良好,但 Android Studio 标志Element LinearLayout is not allowed here。我想知道为什么会这样?我的xml是这样的:

<android.support.v7.widget.CardView
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:layout_below="@id/cv_fb"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            card_view:cardElevation="3dp"
            >

            <LinearLayout

                android:id="@+id/ll_entitlement_extend_google"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:background="@color/white"
                android:clickable="true"
                android:gravity="center"
                android:paddingTop="10dp"
                android:paddingBottom="10dp"
                >

                <ImageView
                    android:layout_weight="1"
                    android:layout_width="75dp"
                    android:layout_height="75dp"
                    android:src="@drawable/google_icon"/>

                <TextView
                    android:layout_weight="1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Connect with Google +"/>

                <ImageView
                    android:layout_weight="1"
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:src="@drawable/ic_chevron_right_black"/>


            </LinearLayout>
        </android.support.v7.widget.CardView>
4

2 回答 2

26

正如@Blacklight在评论中所说,只是为了得到一个正确的答案,这是一个 IDE 问题,因此重新启动它应该可以解决问题。

于 2015-02-06T10:40:58.887 回答
2

除了其他建议和上述答案之外,如果我没有将我的支持库升级到 AndroidX,这个问题就会发生在我身上,在这种情况下是 CardView。所以从

android.support.v7.widget.CardView

将需要更改为

androidx.cardview.widget.CardView

并且警告现在将消失。

在此处输入图像描述

于 2019-08-26T18:34:19.097 回答