android TextView 例子代码(文字图片、文字省略、文字滚动)

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.prize.mydemo1.Main4Activity">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <!--TextView 放入图片例子-->
        <!--android:drawableTop="@drawable/icon1"  在文字上面放入图片-->
        <!--android:drawablePadding="20dp"  设置图片与文字之间的间隔-->
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="努力学习"
            android:textColor="#0000ff"
            android:textSize="50sp"
            android:drawableTop="@drawable/icon1"
            android:drawablePadding="20dp"
            />
        <!--文字太长显示省略。。。例子-->
        <!--android:maxLines="1"  设置TextView行数-->
        <!--android:ellipsize="end"  设置文本结尾显示。。。-->
        <!--android:layout_marginBottom="5dp" 设置布局间隔-->
        <TextView
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:text="@string/main4Text1"
            android:maxLines="1"
            android:ellipsize="end"
            android:layout_marginBottom="5dp"/>
        <!--android:ellipsize="end"  设置文本中间显示省略。。。-->
        <TextView
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:text="@string/main4Text1"
            android:maxLines="1"
            android:ellipsize="middle"/>
        <!--设置有滚动播放效果的文字显示-->
        <!--android:singleLine="true"  设置单行-->
        <!--android:marqueeRepeatLimit="marquee_forever"  设置滚动次数,这里为永久滚动-->
        <!--android:ellipsize="marquee"  ellipsize意思省略位置,marquee的意思是滚动模式-->
        <!--android:focusable="true"  意思可聚焦,被选中。只有聚焦的文字才会滚动-->
        <!--android:focusableInTouchMode="true"   可调焦的触摸模式-->
        <!--注意此方法设置文字滚动,一个页面只有一段文字可以被预设聚焦并且滚动-->
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/main4Text1"
            android:layout_marginTop="30dp"
            android:singleLine="true"
            android:ellipsize="marquee"
            android:marqueeRepeatLimit="marquee_forever"
            android:focusable="true"
            android:focusableInTouchMode="true"/>

    </LinearLayout>

</LinearLayout>
 
 

运行效果:



猜你喜欢

转载自blog.csdn.net/qq_37217804/article/details/79808322