微型技术博客(1)

本次的任务为利用TextView实现跑马特效,代码如下:

strings.xml:

<resources>
    <string name="app_name">这是一个很长很长很长很长很长的句子。Du bist meine Welt.</string>
    <string name="Hello_world" />
</resources>

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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=".MainActivity">

    <TextView
        android:layout_width= "wrap_content"
        android:layout_height = "wrap_content"
        android:text = "@string/app_name"
        android:singleLine="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:ellipsize="marquee"
        android:textSize = "28sp" />

</android.support.constraint.ConstraintLayout>


MainActivity.java:

package com.bignerdranch.android.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}


效果如下:

阅读更多

没有更多推荐了,返回首页