Android开发Android基础捡漏知识点Android开发经验谈

TextView漏的知识点

2018-07-31  本文已影响5人  你的益达233
/**
     * 设置图片大小
     */
    Drawable[] drawables = tvName.getCompoundDrawables();
    drawables[0].setBounds(0,0,80,80);
    tvName.setCompoundDrawables(drawables[0],null,null,null);

    /**
     * 使用Html
     */
    String sMCHtml = "<font color = '"+context.getResources().getColor(R.color.colorAccent)+"'>"+"他是谁"+"</font>";
    tvName.setText(Html.fromHtml(sMCHtml));
    tvName.setMovementMethod(LinkMovementMethod.getInstance());

    /**
     * SpannableString字体多样化
     * 还有点击效果:ClickableSpan
     */
    SpannableString span = new SpannableString("我是谁,我在哪?");
    span.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.colorAccent)),0,span.length(),0);
    tvName.setText(span);

跑马灯效果

<TextView
    android:id="@+id/tv_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你"
    android:layout_centerInParent="true"
    android:ellipsize="marquee"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:singleLine="true"
    android:marqueeRepeatLimit="marquee_forever"
    />
上一篇 下一篇

猜你喜欢

热点阅读