Несколько элементов CardView с использованием линейного макета - PullRequest
0 голосов
/ 22 октября 2018

В настоящее время у меня есть одна карта, которую я пытаюсь разделить на середину.Предполагается, что фотография выровнена по левому краю карты, а затем два текстовых изображения разделены на вид с правой стороны того же самого карты.Я пробовал несколько решений, то есть настройку полей макета, ориентации, layoutmargin_Right, гравитации и т. Д., Но не могу заставить его работать.Любая помощь с благодарностью

   <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>

1 Ответ

0 голосов
/ 22 октября 2018

Если вам нужно представление с двумя столбцами, в котором один из столбцов имеет несколько строк, вы не сможете добиться этого с помощью одного LinearLayout.Вам нужно либо использовать два LinearLayouts (один для столбцов, а другой для строк) или использовать другую группу представлений, например ConstraintLayout.

На данный момент, возможно, самая простая вещь длябыло бы использовать два 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>

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...