TextView 文字切割

TextView Text Cutting

我正在使用 cardview 在我的 android 报价应用程序中显示文本。我的文本是从左侧和右侧剪切的...我已经测试了填充、边距等但没有用。可以看到图片中的文字切割

我的 XML 如下所示...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.CardView
        android:id="@+id/quoteCard"
        android:layout_marginTop="4dp"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:background="@drawable/newbackg"
        android:layout_marginBottom="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:layout_width="match_parent"
        android:elevation="3dp"
        app:cardCornerRadius="6dp"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/cardBackground"
            android:scaleType="fitXY"
            android:background="@drawable/newbackg"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <LinearLayout

            android:id="@+id/quoteCardActionView"
            android:background="?attr/selectableItemBackground"
            android:padding="8dp"
            android:gravity="center"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
                <TextView
                    android:id="@+id/textDetailQuote"
                    android:text="The price of success is hard work, dedication to the job at hand, and the determination that whether we win or lose, we have applied the best of ourselves to the task at hand."
                    android:textSize="@dimen/newMainText"
                    android:lineSpacingExtra="8dp"
                    android:textStyle="bold"
                    android:gravity="center"
                    android:textColor="@color/black"
                    android:typeface="serif"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />


        </LinearLayout>

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

</LinearLayout>

新图片如下所示

请检查并让我知道是否有人可以帮助我解决问题。 谢谢

尝试为 LinearLayout

删除 android:padding="8dp"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.CardView
        android:id="@+id/quoteCard"
        android:layout_marginTop="4dp"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:background="@drawable/newbackg"
        android:layout_marginBottom="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:layout_width="match_parent"
        android:elevation="3dp"
        app:cardCornerRadius="6dp"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/cardBackground"
            android:scaleType="fitXY"
            android:background="@drawable/newbackg"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <LinearLayout
            android:id="@+id/quoteCardActionView"
            android:background="?attr/selectableItemBackground"
            android:gravity="center"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
                <TextView
                    android:id="@+id/textDetailQuote"
                    android:text="The price of success is hard work, dedication to the job at hand, and the determination that whether we win or lose, we have applied the best of ourselves to the task at hand."
                    android:textSize="@dimen/newMainText"
                    android:lineSpacingExtra="8dp"
                    android:textStyle="bold"
                    android:gravity="center"
                    android:textColor="@color/black"
                    android:typeface="serif"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
        </LinearLayout>
    </android.support.v7.widget.CardView>
</LinearLayout>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.CardView
        android:id="@+id/quoteCard"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/disha"
        android:layout_marginBottom="@dimen/activity_horizontal_margin"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:layout_marginTop="4dp"
        android:elevation="3dp"
        app:cardCornerRadius="6dp">

        <ImageView
            android:id="@+id/cardBackground"
            android:background="@drawable/disha"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY" />

        <LinearLayout
            android:id="@+id/quoteCardActionView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="?attr/selectableItemBackground"
            android:gravity="center"
            android:orientation="vertical"
            android:padding="8dp">

            <TextView
                android:id="@+id/textDetailQuote"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:lineSpacingExtra="8dp"
                android:text="સફળતાની કિંમત હાર્ડ કામ છે, નોકરી પરના સમર્પણને, અને નક્કી કરીએ છીએ કે આપણે જીતી કે ગુમાવું, અમે હાથમાં કાર્ય માટે શ્રેષ્ઠ જાતને લાગુ કર્યો છે."
                android:textStyle="bold"
                android:typeface="serif" />


        </LinearLayout>

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


</LinearLayout>

试试这个代码:

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.CardView
            android:id="@+id/quoteCard"
            android:layout_marginTop="4dp"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:background="@color/gray"
            android:layout_marginBottom="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:layout_width="match_parent"
            android:elevation="3dp"
            app:cardCornerRadius="6dp"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/cardBackground"
                android:scaleType="fitXY"
                android:background="@color/orange"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

            <LinearLayout
                android:id="@+id/quoteCardActionView"
                android:background="?attr/selectableItemBackground"
                android:padding="8dp"
                android:gravity="center"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/textDetailQuote"
                    android:text="સફળતાની કિંમત સખત મહેનત, હાથમાં કામ માટે સમર્પણ, અને નક્કી કરીએ છીએ કે આપણે જીતીએ કે ગુમાવવું છે, અમે સફળતા માટેના મૂલ્ય પર કાર્ય માટે જાતને શ્રેષ્ઠ રીતે લાગુ પાડીએ છીએ, મહેનતનું કામ, હાથે કામ માટે સમર્પણ , અને તે નક્કી કરે છે કે આપણે જીતીએ કે ગુમાવું, અમે હાથમાં કાર્ય માટે શ્રેષ્ઠ જાતને લાગુ કર્યો છે."
                    android:textSize="20sp"
                    android:lineSpacingExtra="8dp"
                    android:textStyle="bold"
                    android:gravity="center"
                    android:textColor="@color/black"
                    android:typeface="serif"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>

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

    </LinearLayout>

我对你的XML做了一些修改。

使用这个。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.CardView
        android:id="@+id/quoteCard"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="@dimen/activity_horizontal_margin"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:layout_marginTop="4dp"
        android:background="@color/colorAccent"
        android:elevation="3dp"
        app:cardCornerRadius="6dp">

        <ImageView
            android:id="@+id/cardBackground"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorAccent"
            android:scaleType="fitXY" />

        <LinearLayout

            android:id="@+id/quoteCardActionView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="?attr/selectableItemBackground"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textDetailQuote"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:lineSpacingExtra="8dp"
                android:text="સફળતાની કિંમત હાર્ડ કામ છે, નોકરી પરના સમર્પણને, અને નક્કી કરીએ છીએ કે આપણે જીતી કે ગુમાવું, અમે હાથમાં કાર્ય માટે શ્રેષ્ઠ જાતને લાગુ કર્યો છે."
                android:textColor="@android:color/black"
                android:textSize="22sp"
                android:textStyle="bold"
                android:typeface="serif" />


        </LinearLayout>

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


</LinearLayout>

检查我的设备的屏幕截图,上面使用了 XML。

更改此文本视图,添加左、右填充。

<TextView
        android:id="@+id/textDetailQuote"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:lineSpacingExtra="8dp"
        android:text="સફળતાની કિંમત હાર્ડ કામ છે, નોકરી પરના સમર્પણને, અને નક્કી કરીએ છીએ કે આપણે જીતી કે ગુમાવું, અમે હાથમાં કાર્ય માટે શ્રેષ્ઠ જાતને લાગુ કર્યો છે."
        android:textStyle="bold"
        android:typeface="serif" />

试试这个代码

为背景创建XML

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >

    <gradient
        android:angle="90"
        android:centerColor="#555994"
        android:endColor="#b5b6d2"
        android:startColor="#555994"
        android:type="linear" />

    <corners
        android:radius="0dp"/>

</shape>

your.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.CardView
        android:id="@+id/quoteCard"
        android:layout_marginTop="4dp"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginBottom="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:layout_width="match_parent"
        android:elevation="3dp"
        app:cardCornerRadius="6dp"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/cardBackground"
            android:scaleType="fitXY"
            android:background="@drawable/tests"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <LinearLayout

            android:id="@+id/quoteCardActionView"
            android:background="?attr/selectableItemBackground"
            android:padding="8dp"
            android:gravity="center"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <TextView
                android:id="@+id/textDetailQuote"
                android:text="વિશ્વાસ બધા પર ના કરો સાહેબ
કારણ કે સાકર અને મીઠા નો રંગ એક જ હોય છે."
                android:textSize="18sp"
                android:lineSpacingExtra="8dp"
                android:textStyle="bold"
                android:gravity="center"
                android:textColor="#000000"
                android:typeface="serif"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />


        </LinearLayout>

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

</LinearLayout>

输出