在Cardview中对齐项目 [英] Aligning items in cardview

查看:88
本文介绍了在Cardview中对齐项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的卡外观如下

我保持这样的布局

    <android.support.v7.widget.CardView
        android:layout_gravity="center"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        card_view:cardCornerRadius="2dp"
        >

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Order# GAMH2103"
            android:layout_marginStart="5dp"
            android:layout_marginLeft="5dp"
            android:gravity="start"
            android:textSize="15dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Confirmed"
                android:drawableRight="@drawable/check"
                android:textColor="#00FF00"
                android:gravity="end"
                android:textSize="15dp"/>

        </LinearLayout>
            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@android:color/darker_gray"
                android:layout_marginTop="5dp"
                />

        </LinearLayout>

不知何故,我无法看到已确认" TextView.我可以看到订单号.

Somehow, i am not able to get the "confirmed" TextView visible. I can see the order# though.

我曾经玩过gravitylayout_gravity,但不知怎么过.

I have played with the gravity and layout_gravity but somehow couldn't get through.

请帮助.

谢谢,拉克什曼.

推荐答案

使用以下布局.这将为您工作.

Use the following layout.This will work for you.

始终首选使用相对布局"而不是线性"布局,以实现更好的视图对齐.

It is always preferred to use Relative Layout instead of Linear layout for better view alignment .

<android.support.v7.widget.CardView
    android:layout_gravity="center"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    card_view:cardCornerRadius="2dp">

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Order# GAMH2103"
            android:layout_marginStart="5dp"
            android:layout_marginLeft="5dp"
            android:gravity="start"
            android:textSize="15dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Confirmed"
            android:textColor="#00FF00"
            android:gravity="end"
            android:textSize="15dp"/>


    </RelativeLayout>

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

这篇关于在Cardview中对齐项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆