Text Clipping in Textview

☆樱花仙子☆ 提交于 2019-12-14 03:32:58

问题


I am adding Text in textview but it clipping at start and I have tried adding padding, margin start and textalignment center or end.

XML CODE

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eb2f06"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">

<android.support.v7.widget.CardView
    android:id="@+id/c1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/dim_2"
    android:visibility="invisible"
    app:cardBackgroundColor="#ffeb3b"
    app:cardCornerRadius="@dimen/dim_7"
    app:cardElevation="@dimen/dim_5"
    app:cardUseCompatPadding="true">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="vertical"
            android:padding="@dimen/dim_5">


            <TextView
                android:id="@+id/txtquote"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_margin="@dimen/dim_4"
                android:fontFamily="@font/dancingbold"
                android:padding="@dimen/dim_10"
                android:textColor="#000000"
                android:textSize="35sp" />

            <TextView
                android:id="@+id/txtauthor"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginEnd="@dimen/dim_3"
                android:layout_marginTop="@dimen/dim_3"
                android:fontFamily="@font/dancingbold"
                android:gravity="end"
                android:padding="@dimen/dim_5"
                android:textColor="#000000"
                android:textSize="30sp" />


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

Setting Content in java Java Code

    txtquote.setText("\"" + arrquote.get(count).quote + "\"");
    txtauthor.setText("~" + arrquote.get(count).author);

I have tried using hair space and \u0020

Firstly I thought it is because of my phone small screen but when I tried this in many different screen size phones, It still has the same problem


回答1:


Try adding

android:clipToPadding="false"
android:clipChildren="false"

To the parent layouts of your TextViews.




回答2:


This is about the font properties(italic) and how android can measure/handle them. With that font afaik you won't be able get rid of clipping.




回答3:


Try puting this instead of your scroll view, it will add a little space and i think it will not cut your text.

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="10dp">


来源:https://stackoverflow.com/questions/51283454/text-clipping-in-textview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!