【问题标题】:LinearLayout flagged if used in CardView如果在 CardView 中使用,LinearLayout 会被标记
【发布时间】:2019-08-27 02:34:19
【问题描述】:

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

【问题讨论】:

  • 可能是一些 sdk 故障。清理您的项目并重试
  • 这更像是一个 IDE 故障。清理对我不起作用,但只需重新启动 Android Studio 即可解决此问题。
  • 同样的事情发生在我身上,正如@Blacklight所说,这似乎是一个IDE问题,只需重新启动IDE即可解决它
  • 现在连重启都不行怎么办???我已经重启了整个系统,清理了项目,我也尝试过“无效数据缓存/重启”,现在真的很沮丧.....

标签: android android-layout android-linearlayout android-cardview


【解决方案1】:

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

【讨论】:

【解决方案2】:

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

android.support.v7.widget.CardView

需要改成

androidx.cardview.widget.CardView

警告现在将消失。

【讨论】:

  • 完美,这就是问题所在。谢谢!
猜你喜欢
  • 1970-01-01
  • 2020-07-17
  • 1970-01-01
  • 1970-01-01
  • 2019-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-11
相关资源
最近更新 更多