TextView内容在底部被截断

时间:2019-05-17 21:01:31

标签: android android-layout textview display spacing

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

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

This is how it looks.

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

2 个答案:

答案 0 :(得分:1)

您必须将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>

答案 1 :(得分:0)

对于ellipsize,请尝试添加android:maxlines。 对于剪切线,我需要使用滚动视图。