gpt4 book ai didi

java - 水平居中文本

转载 作者:行者123 更新时间:2023-12-01 09:44:53 24 4
gpt4 key购买 nike

我正在使用 CardView 列出我的引言和作者图片。我试图在列表中的水平中心设置报价。我尝试过重心和相关方法。但我并不成功。我当前的 View 如下所示

当前

enter image description here

需要

enter image description here

我的 XML 如下所示

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">


<android.support.v7.widget.CardView

android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
app:cardElevation="4dp"
app:cardCornerRadius="6dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:id="@+id/quoteActionView"
android:clickable="true"
android:background="?attr/selectableItemBackground"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:visibility="visible"
android:id="@+id/imageAuthorView"
android:scaleType="fitXY"
android:layout_width="150dp"
android:layout_height="150dp" />
<TextView
android:visibility="gone"
android:id="@+id/textIndxQuote"
android:padding="8dp"
android:gravity="center"
android:background="#444444"
android:textColor="@android:color/white"
android:textStyle="bold|italic"
android:textSize="16sp"
android:layout_width="48dp"
android:layout_height="match_parent" />

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

<TextView
android:id="@+id/textQuote"
android:scrollHorizontally="true"
android:ellipsize="end"
android:maxLines="2"
android:textSize="40sp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>

</LinearLayout>

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

请检查并让我知道我缺少什么。

谢谢

最佳答案

将最后一个 LinearLayout 更改为:

   <LinearLayout
android:layout_margin="8dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_gravity="center"
android:layout_height="wrap_content">

关于java - 水平居中文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38146177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com