【发布时间】:2017-07-14 21:12:24
【问题描述】:
我想设计布局,卡片视图垂直堆叠,卡片之间有 3dp 边距,但是当我使用相对视图作为卡片视图的封闭视图时,它没有给出预期的结果,我是 Android 新手。这段代码 sn -p 将帮助您清楚地理解:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.dpl_it.m.hamzam.widgets.MainActivity">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFF"
card_view:cardElevation="3dp">
<ImageView
android:id="@+id/img1"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:gravity="center_horizontal"
android:src="@drawable/bluetooth_connect" />
<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/txt1"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginRight="16dp"/>
<TextView
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
android:layout_toEndOf="@+id/img1"
android:layout_toRightOf="@+id/img1"
android:paddingTop="34dp"
android:text="Bluetooth"
android:textSize="24sp"
android:textStyle="bold"
tools:textColor="#3F51B5" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/card_view1"
android:background="#FFFF"
android:elevation="3dp"
android:layout_alignParentBottom="true">
</android.support.v7.widget.CardView>
</RelativeLayout>
【问题讨论】:
标签: android android-recyclerview android-cardview