gpt4 book ai didi

java - 基线对齐的TextView裁剪多行文本的底行

转载 作者:太空狗 更新时间:2023-10-29 15:11:08 24 4
gpt4 key购买 nike

我希望android应用程序列表视图中的项目在左侧包含一个复选框,后面是一些文本,后面是一个按钮。我希望复选框和按钮与文本对齐。为了实现这一点,我将这三个项都放在一个linearlayout中,该linearlayout在默认情况下尝试基线对齐其项。这很好,除了多行文本的底线总是被剪裁。
下面是它的外观示例:
stackoverflow上有一个related question问题,建议的解决方案是为textview设置layout_gravity=“fill”,但由于它禁用了基线对齐,因此无法达到目的。这个问题有什么解决方法可以让我保持基线对齐吗?这似乎是许多人必须面对的一个基本问题。
我发现的另一个解决方案是在文本视图的底部添加一些填充,但这看起来很老套,而且不适合字体大小。我可以根据字体大小从代码中按程序设置填充,但是要获得正确的值可能会比较困难。
下面是一个说明问题的布局示例:

<?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="wrap_content"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:baselineAligned="true">

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="9dp"
android:layout_marginRight="8dp"
android:textSize="16sp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Woah, this is a long text line, enough that tit has to wrap to multiple lines, thus demonstrating our problem. In fact, it wraps to multiple lines! So many lines! I hope they all show up correctly!"
android:textSize="16sp"/>

<FrameLayout
android:layout_width="40dp"
android:layout_height="match_parent">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="12dp"
android:src="@drawable/ic_note_check_delete"/>
</FrameLayout>
</LinearLayout>

最佳答案

我最后通过将TextView的布局重力更改为center_vertical解决了一个类似的问题。

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />

来自 https://stackoverflow.com/a/11246243/3681880

关于java - 基线对齐的TextView裁剪多行文本的底行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16226354/

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