Android CardView都堆在一起
我正在尝试创建一个应用程序,它将有一个CardView列表。我在标记中添加了三个CardView,如下所示:Android CardView都堆在一起,android,user-interface,android-5.0-lollipop,material-design,Android,User Interface,Android 5.0 Lollipop,Material Design,我正在尝试创建一个应用程序,它将有一个CardView列表。我在标记中添加了三个CardView,如下所示: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="james_parsons.github.io.fblafashionapp.MainActivity">
<android.support.v7.widget.CardView android:layout_width="350dp"
android:layout_height="350dp">
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView android:layout_width="350dp"
android:layout_height="350dp">
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView android:layout_width="350dp"
android:layout_height="350dp">
</android.support.v7.widget.CardView>
</RelativeLayout>
我希望我的卡片像看到的一样垂直堆叠。如何实现这一点?对于您的情况,线性布局最适合您。此外,由于布局可以超过一个屏幕,因此应使用滚动视图将其包装起来。此外,对于RelativeLayout
,child的默认位置是左上角,如果您想要一些不同的内容,则必须指定一些布局属性,例如android:layout\u下方的
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="james_parsons.github.io.fblafashionapp.MainActivity">
<LinearLayout
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView android:layout_width="350dp"
android:layout_height="350dp">
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView android:layout_width="350dp"
android:layout_height="350dp">
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView android:layout_width="350dp"
android:layout_height="350dp">
</android.support.v7.widget.CardView>
</LinearLayout>
<ScrollView>
编辑:
另外,不要完全信任布局预览,尽管这次它应该是正确的。布局预览有时会有一些不准确的限制,您应该只在快速测试时使用,并且只信任真实设备或模拟器中的布局。@VicJordan编辑时,请避免,同时确保您没有创建新的重复标记(你的标签android material design
是material design
的翻版)。谢谢你的理解!