android - CardView 布局重叠

标签 android layout

我有两个卡片 View ,我想将一个放在另一个上面,但最终结果是它们彼此重叠:

enter image description here

这是 XML 代码:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        android:id="@+id/entryTypeCardView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Spinner
            android:id="@+id/entryChoiceSpinner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="10dp" />


    </android.support.v7.widget.CardView>
</RelativeLayout>
<RelativeLayout
    android:layout_width="match_parent"
    android:id="@+id/currencySpinnerLayout"
    android:orientation="vertical"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        android:id="@+id/currencyTypeCardView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">



        <Spinner
            android:id="@+id/currencyChoiceSpinner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="10dp" />
    </android.support.v7.widget.CardView>
</RelativeLayout>


<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent">

    <AutoCompleteTextView
        android:id="@+id/personNameTextField"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
      ...

我做错了什么?

最佳答案

为第一个 RelativeLayout 分配一些 id

<RelativeLayout
android:id="@+id/first_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

然后使用

android:layout_below="@+id/first_layout"

到第二个布局。

关于android - CardView 布局重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31158930/

相关文章:

html - 如何将图片与 css 对齐?

android - 如何为 View 设置动画以隐藏在另一个 View 下方,然后从该 View 设置动画

java - HTTP Get 语句以 URL 中的 { 结束

android - 如何保持显示编辑文本的警报对话框

android - Activity 与 Android 之间的动画

java - BoxLayout 忽略 setYAlighment

html - 与 :hover? 相反

Android 自定义标记图标

android - 如何从公共(public) AsyncTask 获取 MainActivity TextView?

html - 如何在 Dreamweaver 中针对移动设备进行设计,同时在我拥有桌面代码的同一 CSS 中进行编码?