在新的 CardView 中对齐多个 TextView [英] Aligning multiple TextView within new CardView

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

问题描述

我正在尝试创建一个 CardView,它将显示作者的引用,包括作者姓名、引用,然后是其下方的引用.我想我已经掌握了大部分内容,但是对齐 TextView 的一般规则似乎不适用于 CardView.我在这里研究过,发现您应该将 android:layout="vertical" 添加到 LinearLayout(或 RelativeLayout),但这对我来说似乎没有改变.我也尝试将它添加到 CardView 本身,认为它继承了直接父级的方向,但也没有运气.我仍然让 TextViews 相互重叠,而不是一个接一个.

I'm trying to create a CardView that will display a quote by an author, including the author name, the quote, and then the reference below it. I think I've got most of it, but it seems that the general rules for aligning TextViews don't seem to apply to CardView. I've researched here and found that you should add android:layout="vertical" to LinearLayout (or RelativeLayout) but that doesn't seem to change things for me. I've also tried adding it to the CardView itself, thinking that it inherits the orientation from the immediate parent, but also no luck. I still get the TextViews overlapping each other, rather than one after the other.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent">
    ... >

<!-- A CardView that contains a TextView -->
<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"
    android:layout_gravity="top"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:longClickable="true"
    android:orientation="vertical"
    card_view:cardUseCompatPadding="true"
    card_view:cardCornerRadius="4dp"
    card_view:cardElevation="4dp"
    card_view:contentPadding="10dp"
    >
    <TextView
        android:id="@+id/info_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#FF4444"
        android:textSize="24sp"
        android:text="Gordon B. Hinckley"
        />
    <TextView
        android:id="@+id/info_text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/info_text"
        android:text="Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text. Test text."
        />
    <TextView
        android:id="@+id/info_text3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/info_text2"
        android:textColor="#33B5E5"
        android:gravity="end"
        android:text="and I'm the reference."
        />

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

有什么想法吗?

推荐答案

解决了.只需要将 包装在 (或任何其他布局)中,但仍然在 .

Solved it. Just needed to wrap the <TextView>s in a <LinearLayout> (or whatever other layout) but all still within <android.support.v7.widget.CardView>.

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

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