gpt4 book ai didi

android - 在 android L 中的 Cardview 中显示 UI 小部件

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:26:15 24 4
gpt4 key购买 nike

我正在尝试在 cardview 中创建一个应用程序,cardview 包含两个需要彼此相邻放置的 TextView ,但 TextView 正在重叠。是否有任何机制可以像在 Cardviews 的 RelativeLayout(layout_below 或 layout_toRightOf) 中那样放置元素。我可以通过向 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>

目前显示如附图:

enter image description here

最佳答案

来自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 中, View 定位之间没有约束或关系。它们将一个一个地显示在彼此之上。如果您想在 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 L 中的 Cardview 中显示 UI 小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25500746/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com