首页 > 解决方案 > TextView 内容在底部被截断

问题描述

在我的应用程序中,指定为 R.id.text3 的 TextView 确实会切断其内容,有时会显示半行。此外, ellipsize 也不起作用。从布局中,您是否看到我必须添加的内容,以便 Text 释放截止线并且(在最好的情况下)最后也省略了?

如果您可能需要我的 CursorAdapter 代码,请随时索取!顺便说一句,我还在“linearLayout”上定义了一个填充以匹配导航栏。

这就是它的外观。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:airbnb="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?android:attr/windowBackground"
android:foreground="?android:attr/selectableItemBackground"
android:id="@+id/baseRelativeLayout"
android:focusable="true"
android:clickable="true"
android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:id="@+id/linearLayout"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/relative_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:clickable="false"
        android:layout_marginTop="5dp"
        android:minHeight="80dp">

        <ImageView
            android:id="@+id/main_icon"
            android:layout_width="@dimen/entry_img_size"
            android:layout_height="@dimen/entry_img_size"
            android:layout_centerVertical="true"
            app:shapeAppearance="@style/ShapeAppearance.Daily.MediumComponent"
            android:layout_marginLeft="16dp"
            android:clickable="true"
            android:scaleType="centerCrop"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="10dp"
            android:id="@+id/titleLinearLayout"
            android:layout_toRightOf="@+id/main_icon"
            android:orientation="vertical">

            <TextView
                android:id="@android:id/text1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawablePadding="3dp"
                android:ellipsize="end"
                android:gravity="top"
                android:maxLines="3"
                android:textSize="28sp"
                android:textColor="?attr/contentColor"
                android:clickable="true"
                android:textStyle="bold"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textIsSelectable="false"/>

            <TextView
                android:id="@android:id/text2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:alpha="0.7"
                android:textColor="?attr/contentColor"
                android:drawablePadding="3dp"
                android:singleLine="true"
                android:clickable="true"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textIsSelectable="false"/>

        </LinearLayout>

        <com.airbnb.lottie.LottieAnimationView
            android:id="@+id/favorite_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:paddingTop="10dp"
            airbnb:lottie_fileName="star.json"
            airbnb:lottie_scale="0.3"
            airbnb:lottie_autoPlay="false"
            airbnb:lottie_loop="false"
            android:layout_alignParentEnd="true" />

    </RelativeLayout>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:visibility="gone"
        android:clickable="true"
        android:layout_gravity="center_horizontal"
        android:scaleType="fitStart"
        android:adjustViewBounds="true"
        android:layout_marginBottom="5dp"
        android:maxHeight="500dp"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:focusable="true" />

    <TextView
        android:id="@+id/text3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="1dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:ellipsize="end"
        android:textColor="?attr/contentColor"
        android:textSize="18sp"
        android:focusable="false"
        android:clickable="false"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textIsSelectable="false"/>


</LinearLayout>

标签: androidandroid-layouttextviewdisplayspacing

解决方案


你必须把你的 LinearLayout(linearLayout) 放在一个ScrollView

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
         android:layout_width="match_parent"
         android:orientation="vertical"
         android:id="@+id/linearLayout"
         android:layout_height="match_parent">

              <....
              ....>

    </LinearLayout>

</ScrollView>

推荐阅读