资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

android横向滚动,android横向滚动 分段

android文字横向滚动的自定义view

这还不简单吗?直接加个动画就行了!

成都创新互联公司服务项目包括秦淮网站建设、秦淮网站制作、秦淮网页制作以及秦淮网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,秦淮网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到秦淮省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

现在我做下补充:

package com.qiulong.textscrolldemo;

import android.content.Context;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.util.AttributeSet;

import android.view.View;

public class CustomScrollText extends View {

//背景画笔

private Paint backPaint;

//背景颜色

private int backColor = Color.GRAY;

//文本画笔

private Paint textPaint;

//字体颜色

private int textColor = Color.BLACK;

//字体大小

private int textSize = 20;

//文字内容

private String textContent = "textView";

//X轴偏移量

private float OffsetX = 0;

//刷新线程

private RefreshRunnable mRefreshRunnable;

public CustomScrollText(Context context) {

super(context);

init();

}

public CustomScrollText(Context context, AttributeSet attrs) {

super(context, attrs);

init();

}

public CustomScrollText(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);

init();

}

/**

 * 初始化画笔

 */

private void init(){

backPaint = new Paint();

backPaint.setAntiAlias(true);

backPaint.setColor(backColor);

backPaint.setStyle(Paint.Style.FILL);

textPaint = new Paint();

textPaint.setAntiAlias(true);

textPaint.setColor(textColor);

textPaint.setStyle(Paint.Style.FILL);

textPaint.setTextSize(textSize);

}

@Override

protected void onAttachedToWindow() {

super.onAttachedToWindow();

//启动刷新

mRefreshRunnable = new RefreshRunnable();

post(mRefreshRunnable);

}

@Override

protected void onDetachedFromWindow() {

super.onDetachedFromWindow();

//关闭刷新

removeCallbacks(mRefreshRunnable);

}

@Override

protected void onDraw(Canvas canvas) {

super.onDraw(canvas);

//绘制背景

canvas.drawRect(0, 0, getWidth(), textSize+10, backPaint);// 长方形

//绘制文本内容

canvas.drawText(textContent, OffsetX, textSize, textPaint);

}

/**

 * 测量控件宽高 

 */

@Override

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

int width = measure(widthMeasureSpec);

int height = measure(heightMeasureSpec);

setMeasuredDimension(width, height);

}

private int measure(int measureSpec) {

int specMode = MeasureSpec.getMode(measureSpec);

int specSize = MeasureSpec.getSize(measureSpec);

int result = 70;

if (specMode == MeasureSpec.AT_MOST) {//最大可获空间

result = specSize;

} else if (specMode == MeasureSpec.EXACTLY) {//精确尺寸

result = specSize;

}

return result;

}

/**

 * 刷新线程

 * @author qiulong

 *

 */

private class RefreshRunnable implements Runnable {

public void run() {

synchronized (CustomScrollText.this) {

OffsetX--;

//获取字体宽度

float txtWidth = textPaint.measureText(textContent, 0, textContent.length());

if((0 - OffsetX) = txtWidth){

OffsetX = getWidth();

}

invalidate();

postDelayed(this, 5);

}

}

}

/**

 * 设置文本内容

 * @param value

 */

public void setTextContent(String value){

this.textContent = value;

}

/**

 * 获取文本内容

 * @return

 */

public String getTextContent(){

return textContent;

}

/**

 * 设置文本颜色

 * @param color

 */

public void setTextColor(int color){

this.textColor = color;

textPaint.setColor(textColor);

}

/**

 * 获取文本颜色

 * @return

 */

public int getTextColor(){

return textColor;

}

/**

 * 设置文本大小

 * @param size

 */

public void setTextSize(int size){

this.textSize = size;

textPaint.setTextSize(textSize);

}

/**

 * 获取文本大小

 * @return

 */

public int getTextSize(){

return textSize;

}

/**

 * 设置背景颜色

 */

public void setBackgroundColor(int color){

this.backColor = color;

backPaint.setColor(backColor);

}

/**

 * 获取背景颜色

 * @return

 */

public int getBackgroundColor(){

return backColor;

}

}

下面是MainActivity.class :

package com.qiulong.textscrolldemo;

import android.os.Bundle;

import android.app.Activity;

import android.graphics.Color;

public class MainActivity extends Activity {

private CustomScrollText mtext;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mtext = (CustomScrollText)findViewById(R.id.mtext);

mtext.setTextContent("你加个我看看,说谁都会说,你怎么不干脆说让他直接滚动起来就好了,回答问题也要有点诚意好不");

mtext.setTextSize(30);

mtext.setTextColor(Color.BLUE);

mtext.setBackgroundColor(Color.GREEN);

}

}

然后至于你说的速度控制方面,也很简单!你可以尝试修改下,我就不一五一十的全帮你写了!另外还有一个你说的信息间距我没搞懂是什么意思!

如何实现android中横向滚动的gridView

法1.直接用tablelayout gridview是根据你每行的单元数自动生成的行数;

法2.可以在代码里根据view数来动态设置列数,比如有10记录可以设置列数为10/3+1,这样就有三行四列了。

如果您对我的回答有不满意的地方,还请您继续追问;

答题不易,互相理解,互相帮助!

android 手势判断是横向滑动还是纵向 csdn

对于Android中的手势识别可以从以下三个Listener入手——OnTouchListener、OnGestureListener、OnDoubleTapListener。这三个监听器分别是触摸监听、手势滑动监听和屏幕双击操作监听。很多的时候我们需要这些手势识别的操作,例如我们自定义控件的时候就经常会用到。下面就对这三个监听器分别进行介绍。

触摸监听器OnTouchListener

让我们的Activity去现实此接口,并重写onTouch方法。重写OnTouchListener的onTouch方法 此方法在触摸屏被触摸,即发生触摸事件(接触和抚摸两个事件)的时候被调用。示范代码如下:

@Override

public boolean onTouch(View v, MotionEvent event) {

detector.onTouchEvent(event);

Toast.makeText(this, "onTouch", TIME_OUT).show();

return true;

}

手势滑动监听器OnGestureListener

让我们的Activity去现实此接口,并重写onFling、onLongPress、onScroll、onDown、onShowPress、onSingleTapUp方法。示范代码如下:

/**

* 手势滑动时别调用

*/

@Override

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,

float velocityY) {

if (e1.getX() - e2.getX() FLING_MIN_DISTANCE) {

Toast.makeText(this, "向左滑动", TIME_OUT).show();

} else if (e2.getX() - e1.getX() FLING_MIN_DISTANCE) {

Toast.makeText(this, "向右滑动", TIME_OUT).show();

}

return false;

}

/**

* 长按时被调用

*/

@Override

public void onLongPress(MotionEvent e) {

Toast.makeText(this, "触发长按回调", TIME_OUT).show();

}

/**

* 滚动时调用

*/

@Override

public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,

float distanceY) {

Toast.makeText(this, "触发滚动回调", TIME_OUT).show();

return false;

}

/**

* 在按下动作时被调用

*/

@Override

public boolean onDown(MotionEvent e) {

Toast.makeText(this, "按下回调", TIME_OUT).show();

return false;

}

/**

* 按住时被调用

*/

@Override

public void onShowPress(MotionEvent e) {

Toast.makeText(this, "按住不松回调", TIME_OUT).show();

}

/**

* 抬起时被调用

*/

@Override

public boolean onSingleTapUp(MotionEvent e) {

Toast.makeText(this, "触发抬起回调", TIME_OUT).show();

return false;

}

双击屏幕监听器OnDoubleTapListener

让我们的Activity去现实此接口,并重写onDoubleTap、onDoubleTapEvent、onSingleTapConfirmed方法。示范代码如下:

@Override

public boolean onDoubleTap(MotionEvent arg0) {

Toast.makeText(this, "触发双击回调", TIME_OUT).show();

return false;

}

@Override

public boolean onDoubleTapEvent(MotionEvent arg0) {

Toast.makeText(this, "触发双击的按下跟抬起回调", TIME_OUT).show();

return false;

}

@Override

public boolean onSingleTapConfirmed(MotionEvent arg0) {

Toast.makeText(this, "触发单击确认回调", TIME_OUT).show();

return false;

}

Android中TextView如何实现水平和垂直滚动

殇 殇云的专栏 云的专栏 软件开发 软件开发 一 一、只想让TextView显示一行,但是文字超过 、只想让TextView显示一行,但是文字超过 在开头显示省略号 android:singleLine="true" android:ellipsize="start" 在结尾显示省略号 android:singleLine="true" android:ellipsize="end" 在中间显示省略号 android:singleLine="true" android:ellipsize="middle" 横向自动滚动(跑马灯效果) android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:focusable="true" android:focusableInTouchMode="true" 以上4个效果都要加上�0�2android:singleLine="true",因为TextView默认是会自动换行的 android:marqueeRepeatLimit="marquee_forever"是设置永远重复,当然你也可以设置具体的数字 android:focusable="true"和android:focusableInTouchMode="true"一定要加上,不然滚动效果出不来在Java代码中加入下面一句话就可以实现垂直滚动

android TextView文本动画横向移动时间

TextView实现文字滚动需要以下几个要点:

1.文字长度长于可显示范围:android:singleLine="true"

2.设置可滚到,或显示样式:android:ellipsize="marquee"

3.TextView只有在获取焦点后才会滚动显示隐藏文字,因此需要在包中新建一个类,继承TextView。重写isFocused方法,这个方法默认行为是,如果TextView获得焦点,方法返回true,失去焦点则返回false。跑马灯效果估计也是用这个方法判断是否获得焦点,所以把它的返回值始终设置为true。

Java语言: AlwaysMarqueeTextView 类

public class AlwaysMarqueeTextView extends TextView {

public AlwaysMarqueeTextView(Context context) {

super(context);

}

public AlwaysMarqueeTextView(Context context, AttributeSet attrs) {

super(context, attrs);

}

public AlwaysMarqueeTextView(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);

}

@Override

public boolean isFocused() {

return true;

}

在布局XML文件中加入这么一个AlwaysMarqueeTextView,这个加入方法也是刚刚学的。

XML语言: layout.xml

com.examples.AlwaysMarqueeTextView

android:id=“@+id/AMTV1″

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:lines=“1″

android:focusable=“true”

android:focusableInTouchMode=“true”

android:scrollHorizontally=“true”

android:marqueeRepeatLimit=“marquee_forever”

android:ellipsize=“marquee”

android:background=“@android:color/transparent”

/

ellipsize属性

设置当文字过长时,该控件该如何显示。有如下值设置:”start”—–省略号显示在开头;”end”——省略号显示在结尾;”middle”—-省略号显示在中间;”marquee” ——以跑马灯的方式显示(动画横向移动)

marqueeRepeatLimit属性

在ellipsize指定marquee的情况下,设置重复滚动的次数,当设置为marquee_forever时表示无限次。

组合View的问题:

XML语言: 组合View

LinearLayout

xmlns:android =“”

android:orientation =“vertical”

android:gravity =“center_vertical”

android:background =“@drawable/f_background”

android:layout_width =“fill_parent”

android:focusable =“true”

android:layout_height =“50px”

TextView

android:id =“@+id/info_text”

android:focusable =“true”

android:layout_width =“fill_parent”

android:layout_height =“wrap_content”

android:text =“test marquee .. “

android:textColor =“@color/black”

android:singleLine =“true”

android:ellipsize =“marquee”

android:marqueeRepeatLimit =“3″

android:textSize =“18sp”

/

TextView

android:id =“@+id/date_text”

android:layout_width =“fill_parent”

android:layout_height =“wrap_content”

android:layout_gravity =“bottom”

android:textColor =“@color/gray”

android:text =“2010/05/28″

android:textSize =“12sp”

/

/ LinearLayout

上面示例中2个TextView组合为一个View,由于设置了LinearLayout为focusable而TextView就没法取得焦点了,这样 这个TextView的跑马灯效果就显示不出来,就算你也设置TextView的 android:focusable="true" 也是 没用的. 这个时候就要使用addStatesFromChildren 这个属性了,在LinearLayout中设置这个属性,然后设置TextView的focusable= "true" 就可以了.关于 addStatesFromChildren的说明:

Sets whether this ViewGroup's drawable states also include its children's drawable states.

Android ListView列表如何横向滚动

如果在你的源码基础上改好像不太可能,你把textview改成多行显示吧


文章标题:android横向滚动,android横向滚动 分段
分享路径:http://cdkjz.cn/article/phcjse.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220