0

我需要创建一个从屏幕一端移动到屏幕底部的另一端的视图。意味着像在新频道中的快闪新闻在底部连续移动。类似的概念是我想要的。我不知道要使用什么小部件。我尝试了翻转器,但只有 1 个文本视图被另一个替换。我需要它从一端移动到另一端并更改内容。任何人都可以帮忙吗?

我尝试使用 marquee 使用下面提到的答案..但它仍然没有移动..

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
     t = (TextView) findViewById(R.id.label); 
      t.setSelected(true);
}

//xml

LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
 >


<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:text="@string/hello_world"
android:marqueeRepeatLimit="marquee_forever"
 android:singleLine="true"
/>

有效。问题实际上是我给了一个非常小的字符串(你好世界)现在我给了一个新的长字符串。所以它起作用了

4

3 回答 3

1

看看吧:

xml文件:

<TextView

android:id="@+id/myTextView"

android:ellipsize="marquee" 

android:singleLine="true"/>

在代码中:

tv = (TextView) findViewById(R.id.myTextView);

tv.setSelected(true);

在这里你必须把 textview 作为单行

于 2013-02-22T09:45:15.023 回答
1

你可以这样做。

xml 为TextView

<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

如果你想做一个股票行情

textView.setSelected(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);

        }
    }   
}
于 2013-02-21T11:31:28.673 回答
0

我不完全理解您想要实现的目标,但显然您有两种选择:

创建自己的视图:http: //developer.android.com/training/custom-views/index.html

或创建一些动画并使用现有视图:http: //developer.android.com/training/animation/index.html

于 2013-02-21T11:17:43.020 回答