【问题标题】:TextView Text CuttingTextView 文本切割
【发布时间】:2017-05-31 09:48:12
【问题描述】:

我正在使用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>

新图像如下所示

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

【问题讨论】:

  • 设置左右边距TextView
  • 我认为这是因为您在 card viewimage view 中使用的背景。你可以发布你的背景图片吗?尝试从card view 中删除背景并检查一次。
  • @jaydroider 没有任何变化......
  • 请粘贴您的图片@drawable/newbackg @Manisha
  • 但实际上不错的报价!并检查我的答案。

标签: java android android-layout android-cardview


【解决方案1】:

我对你的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 检查我的设备的屏幕截图。

【讨论】:

  • @ManishaPandey 让你检查我的设备屏幕截图。我已经添加了。
  • @jaydroider 他有背景图片
  • @AdityaVyas-Lakhan 我知道兄弟,但我已经问过了。您可以在 OP 中查看我的评论。但是还没有发图。 OP可以在上面的xml中进行更改和添加图像。
  • @jaydroider 请检查我的问题...我已经更新了图片
  • @ManishaPandey 检查我的答案。我使用图像作为背景。
【解决方案2】:

尝试为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>

【讨论】:

  • 没有任何变化 :(
  • 我认为你应该检查边距。
  • 是的,我也觉得她必须正确验证填充和边距,如果对您有帮助,请投票。
【解决方案3】:
    <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>

【讨论】:

  • 我仍然面临同样的问题...没有任何变化...只是 imageview 消失了
【解决方案4】:

试试这个代码:

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

【讨论】:

    【解决方案5】:

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

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

    【讨论】:

    • 你必须给保证金。
    【解决方案6】:

    试试这个代码

    为背景创建 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>
    

    你的.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>
    

    输出

    【讨论】:

    • 在您的图像视图中添加adjustviewbound true..并检查它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-26
    • 2022-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多