android - 在 cardview 中对齐项目

标签 android android-layout android-linearlayout android-cardview

我希望我的卡片看起来像下面这样

enter image description here

我的布局是这样的

    <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 可见。不过我可以看到订单号。

我玩过 gravitylayout_gravity 但不知何故无法通过。

请帮忙。

谢谢,拉克什曼。

最佳答案

使用以下布局。这对您有用。

为了更好的 View 对齐,总是首选使用相对布局而不是线性布局。

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

关于android - 在 cardview 中对齐项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36169090/

相关文章:

android - Android Gradle 插件无法识别 SourceSet 'instrumentTest'

android - 设置应用程序 :layout_behavior programmatically

android - 更改背景是否也会更改 LinearLayout 的填充?

android - 线性布局权重

java - WiFi 断开时播放音乐

android - 使用 Gradle : Class XYZ is not accessible through the ClassLoader 为多模块项目设置 SonarQube 5.4

c# - Xamarin.android GUI 在 AddView 后不更新

android - 以编程方式在相对布局中定位按钮

Android:列表元素,固定布局

android - 来自 url 的 LinearLayout setBackgroundDrawable 位图