Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在Android L中的Cardview中显示UI小部件大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试在cardview中创建一个应用程序,cardview包含两个需要彼此相邻放置的文本视图,但是文本视图正在重叠.有没有任何机制可以将相同的元素放在RelativeLayout(layouT_Below或layout_toRightOf)中,用于Cardview.
我可以通过向Relativelayout添加阴影并使其看起来像Cardview来实现这一点,我想在Cardview中执行此操作.

我的布局代码如下:

<RelativeLayout xmlns:android="http://scheR_654_11845@as.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:BACkground="@android:color/black"
    android:layout_height="match_parent">

    <android.support.v7.widget.CardView
        android:id="@+id/card_view"
        android:BACkground="@color/white"
        android:layout_width="200dp"
        android:layout_height="200dp">

        <TextView
            android:id="@+id/info_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Textview one"
            android:gravity="center"
            android:textSize="36sp" />
        <TextView
            android:id="@+id/info_text1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Textview two"
            android:gravity="center"
            android:textSize="36sp" />
    </android.support.v7.widget.CardView>
</RelativeLayout>

目前显示如下附图:

解决方法

CardView的描述

您可能知道,在FrameLayout中,视图定位之间没有约束或关系.它们将一个显示在彼此之上.如果您想在CardView中使用不同的层次结构,请使用您想要的任何布局.例如:

<android.support.v7.widget.CardView
    android:id="@+id/card_view"
    android:BACkground="@color/white"
    android:layout_width="200dp"
    android:layout_height="200dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:id="@+id/info_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Textview one"
            android:gravity="center"
            android:textSize="36sp" />
        <TextView
            android:id="@+id/info_text1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Textview two"
            android:gravity="center"
            android:textSize="36sp" />
    </LinearLayout>

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

仅将CardView视为外部装饰,您可以在其中使用任何布局.因此,如果LinearLayout不合适,您可以使用RelativeLayout等.

大佬总结

以上是大佬教程为你收集整理的在Android L中的Cardview中显示UI小部件全部内容,希望文章能够帮你解决在Android L中的Cardview中显示UI小部件所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。