【问题标题】:Android textview not scaledAndroid textview 未缩放
【发布时间】:2014-04-03 09:53:25
【问题描述】:

我的布局有问题。我的 textview 包含文本,在屏幕上看的有点多。我在设备上看不到的文字被剪掉了。如何设置 textview 比例,我可以看到整个文本?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    android:orientation="vertical" >

            <HorizontalScrollView
                android:id="@+id/horizontalScrollView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:orientation="horizontal" >



                    <RelativeLayout
                        android:id="@+id/l1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="horizontal" >

                        <ImageView
                            android:id="@+id/imageView2"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:scaleType="centerInside"
                            android:src="@drawable/crunch1" />

                        <ImageView
                            android:id="@+id/button2links"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/imageView2"
                            android:layout_centerHorizontal="true"
                            android:scaleType="centerInside"
                            android:src="@drawable/links2" />


                        <ImageView
                            android:id="@+id/imageView1"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:src="@drawable/crunch2" />

                        <ImageView
                            android:id="@+id/button2rechts"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/imageView1"
                            android:layout_centerHorizontal="true"                            
                            android:src="@drawable/rechts2" />
                    </RelativeLayout>

            </HorizontalScrollView>

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:text="Crunch"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:layout_below="@+id/horizontalScrollView1" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/crunch" 
                android:layout_below="@+id/textView2"
                android:layout_above="@+id/pause"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"/>

            <ImageButton
                android:id="@+id/pause"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"                
                android:onClick="verlaufKlick"
                android:src="@drawable/ic_launcher"
                android:visibility="invisible"
                android:background="?android:selectableItemBackground"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"

                />


</RelativeLayout>

问题只出在TextView:android:id="@+id/textView1"

【问题讨论】:

    标签: android textview scale


    【解决方案1】:

    您已将该 TextView 的高度设置为 0dp。如果您将高度设置为 0dp,则需要设置权重,否则将高度设置为包装内容。

    【讨论】:

    • 我设置了 wrap_content 而不是 android:layout_height="0dp",但是文字也被剪掉了。
    • 如果你想将文本设置在中心设置重力而不是 textview 的 scaletype
    • 不,我希望我能看到我的所有文本,在第二个快照中缺少文本。
    【解决方案2】:

    文本是水平裁剪还是垂直裁剪?

    scaleType 适用于 ImageView 而不是 TextView。在TextView 上,您可以使用scaleXscaleY。 但是你应该根据屏幕大小设置不同的文字大小

    【讨论】:

    • 在 xml 中。您使用尺寸设置 textSize 。并且您可以根据屏幕尺寸具有不同的尺寸(通过将它们放置在不同的值文件夹中)
    • adjustViewBounds 也是一个 ImageView 属性
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 1970-01-01
    • 2014-10-21
    • 1970-01-01
    • 2015-04-28
    • 1970-01-01
    相关资源
    最近更新 更多