在Android L中的Cardview中显示UI小部件

我正在尝试在cardview中创建一个应用程序,cardview包含两个需要彼此相邻放置的文本视图,但是文本视图正在重叠.有没有任何机制可以将相同的元素放在RelativeLayout(layout_below或layout_toRightOf)中,用于Cardview.
我可以通过向Relativelayout添加阴影并使其看起来像Cardview来实现这一点,我想在Cardview中执行此操作.

我的布局代码如下:

<RelativeLayout xmlns:android="http://schemas.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的描述

CardView extends the FrameLayout class and lets you show information
inside cards that have a consistent look on any app. CardView widgets
can have shadows and rounded corners.

您可能知道,在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轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内...