简体   繁体   English

使用线性布局的多个CardView元素

[英]Multiple CardView Elements Using Linear Layout

I currently have one cardview that I am trying to basically split down the middle. 我目前有一张Cardview,我试图将其分解为中间部分。 The photo is supposed to align to the left of the cardview, then the two text views are divided by a View on the right hand side of that same cardview. 该照片应与卡片视图的左侧对齐,然后将两个文本视图除以同一卡片视图右侧的视图。 I have tried multiple solutions ie adjusting the layout margins, orientations, layoutmargin_Right, gravity etc but can't get it working. 我尝试了多种解决方案,例如调整布局边距,方向,layoutmargin_Right,重力等,但无法使其正常工作。 Any help greatly appreciated thank you 任何帮助,不胜感激谢谢

   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal">


        <android.support.v7.widget.CardView
            android:id="@+id/infoCard"
            android:layout_width="390dp"
            android:layout_height="120dp"
            android:layout_margin="10dp"
            android:clickable="true"
            android:foreground="?android:attr/selectableItemBackground">

            <LinearLayout
                android:layout_width="464dp"
                android:layout_height="match_parent"
                android:orientation="vertical"
                >

                <ImageView
                    android:id="@+id/imgInfo"
                    android:layout_width="51dp"
                    android:layout_height="89dp"
                    android:layout_gravity="left"
                    android:orientation="horizontal"
                    android:layout_marginStart="5dp"
                    android:layout_marginLeft="5dp"

                    android:src="@drawable/infooooo" />

                <TextView
                    android:id="@+id/txtFindOut"
                    android:layout_width="wrap_content"
                    android:layout_height="30dp"
                    android:orientation="horizontal"
                    android:text="Step One: Find Out More"
                    android:layout_marginTop="10dp"
                    android:textSize="17sp"
                    android:gravity="top"
                    android:textStyle="bold" />

                <View
                    android:layout_width="100dp"
                    android:layout_height="1dp"
                    android:layout_margin="10dp"
                    android:layout_alignRight="@+id/imgInfo"
                    android:layout_below="@+id/imgInfo"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="Step One"
                    android:textColor="@android:color/darker_gray"
                    android:textSize="15sp" />

            </LinearLayout>
        </android.support.v7.widget.CardView>
    </LinearLayout>

If you want a two-column view where one of the columns has multiple rows, then you can't achieve this with a single LinearLayout . 如果您想要一个两列视图,其中一列具有多个行,则无法使用单个LinearLayout来实现。 You either need to use two LinearLayouts (one for the columns, and one for the rows) or you need to use a different view group, like ConstraintLayout . 您要么需要使用两个LinearLayouts (一个用于列,一个用于行),要么需要使用其他视图组,例如ConstraintLayout

For now, probably the simplest thing to do would be to use two LinearLayouts. 目前,最简单的操作可能是使用两个LinearLayouts。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#caf"/>

    <View
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:background="#fff"/>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#fca"/>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#fff"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#afc"/>

    </LinearLayout>

</LinearLayout>

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM