Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中的字幕文本,显示来自数组的文本_Android - Fatal编程技术网

android中的字幕文本,显示来自数组的文本

android中的字幕文本,显示来自数组的文本,android,Android,如何以一定的间隔和步长水平或垂直选框文本?。文本是从数组中显示的。这将帮助您水平选框 <TextView android:id="@+id/scroller" android:layout_width="fill_parent" android:layout_height="wrap_content" android:lines="1" android:ellipsize="marquee" android:marqueeRepea

如何以一定的间隔和步长水平或垂直选框文本?。文本是从数组中显示的。

这将帮助您水平选框

<TextView
    android:id="@+id/scroller" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:lines="1" 
    android:ellipsize="marquee" 
    android:marqueeRepeatLimit="marquee_forever" 
    android:scrollHorizontally="true"
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:text="text that is longer than the view"></TextView>

您可以按如下方式进行水平滚动

TextView的xml

<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true" />
如果你想阻止它

textView.setSelected(false);
我假设您正在从ListActivity扩展活动。在onListItemClick中执行以下操作

public void onListItemClick(ListView parent, View row, int position, long id) {

TextView textViewOne =   (TextView)row.findViewById(R.id.text_view);
textViewOne.setSelected(true);
for (int i = 0; i < parent.getChildCount(); i++) {
    if(i!=position){
        View view = (View) parent.getChildAt(i).findViewById(R.id.view);

        textViewOne = (TextView)view.findViewById(R.id.text_view);
        textViewOne.setSelected(false);

    }
}   

}我不确定我是否正确理解了你的问题。可以使用x和y位置在cusotm视图上绘制文本。更改x和y位置并调用invalidate刷新绘图。 下面的示例移动文本hello。。。从右到左

public class MainActivity extends Activity {
float x,y;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    DrawingView dv= new DrawingView(this);
    setContentView(dv); 
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
class DrawingView extends View
{
    Context mcontext;
    Paint mPaint;
    Display display ;
    public DrawingView(Context context) {
        super(context);
        mPaint = new Paint();
        mPaint.setColor(Color.RED);
        mPaint.setTextSize(50f);
        mcontext=context;
         display = ( (Activity) mcontext).getWindowManager().getDefaultDisplay();  
        x = display.getWidth()-mPaint.getTextSize(); 
        //y = display.getHeight();
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);

        canvas.drawText("hello.....",x, 40, mPaint);
        marquee();
    }
    public void marquee()
    {
        if(x>0-mPaint.getTextSize())
        {
            x=x-20;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            invalidate();
        }
        else if(x<=0)
        {
              x = display.getWidth()-mPaint.getTextSize(); 
              invalidate();
        }


    }
}

你试了什么?在提出问题之前,您搜索了什么?主要活动是否也需要更改?因为您上面提供的代码似乎不起作用。请将您在android中提供的文本设置为syour:文本比您的屏幕大小长。当它超出你的屏幕边缘时,它会开始选框。但是如果我的文本很短,那就无法达到目的了,对吗?我想欢迎您在我的屏幕上选框。有没有办法对较小的文本长度执行相同的操作?@GarimaTiwari,我需要查看一下。为什么不在应用程序顶部嵌入一个网络视图,并在其中嵌入文本?
public class MainActivity extends Activity {
float x,y;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    DrawingView dv= new DrawingView(this);
    setContentView(dv); 
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
class DrawingView extends View
{
    Context mcontext;
    Paint mPaint;
    Display display ;
    public DrawingView(Context context) {
        super(context);
        mPaint = new Paint();
        mPaint.setColor(Color.RED);
        mPaint.setTextSize(50f);
        mcontext=context;
         display = ( (Activity) mcontext).getWindowManager().getDefaultDisplay();  
        x = display.getWidth()-mPaint.getTextSize(); 
        //y = display.getHeight();
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);

        canvas.drawText("hello.....",x, 40, mPaint);
        marquee();
    }
    public void marquee()
    {
        if(x>0-mPaint.getTextSize())
        {
            x=x-20;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            invalidate();
        }
        else if(x<=0)
        {
              x = display.getWidth()-mPaint.getTextSize(); 
              invalidate();
        }


    }
}