ami*_*hgc 121 android textview
我试过使用marquee,它不在这里工作是我的代码,请让我知道我哪里出错了
<TextView
android:text="lunch 20.00 | Dinner 60.00 | Travel 60.00 | Doctor 5000.00 | lunch 20.00 | Dinner 60.00 | Travel 60.00 | Doctor 5000.00"
android:id="@+id/TextView02"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:marqueeRepeatLimit="marquee_forever"
android:ellipsize="marquee"
android:singleLine="true"
android:focusable="true"
android:inputType="text"
android:maxLines="1">
</TextView>
Run Code Online (Sandbox Code Playgroud)
我正在使用android SDK 2.0.1
ami*_*hgc 255
现在工作:)下面附带的代码
<TextView
android:text="START | lunch 20.00 | Dinner 60.00 | Travel 60.00 | Doctor 5000.00 | lunch 20.00 | Dinner 60.00 | Travel 60.00 | Doctor 5000.00 | END"
android:id="@+id/MarqueeText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:paddingLeft="15dip"
android:paddingRight="15dip"
android:focusable="true"
android:focusableInTouchMode="true"
android:freezesText="true">
Run Code Online (Sandbox Code Playgroud)
编辑(代表Adil Hussain):
textView.setSelected(true) 需要在后面的代码中设置才能使其工作.
Sha*_*dul 84
android:singleLine="true"
android:ellipsize="marquee"
Run Code Online (Sandbox Code Playgroud)
是唯一必需的属性和滚动甚至与layout_weight定义的工作layout_width=0dp
这是一些示例代码:
<TextView
android:id="@+id/scroller"
android:singleLine="true"
android:ellipsize="marquee"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:text="Some veryyyyy long text with all the characters that cannot fit in screen, it so sad :( that I will not scroll"
android:layout_marginLeft="4dp"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content"
/>
Run Code Online (Sandbox Code Playgroud)
但最重要的是隐含或明确TextView 应该被选中.
你可以这样做:
TextView txtView=(TextView) findViewById(R.id.scroller);
txtView.setSelected(true);
Run Code Online (Sandbox Code Playgroud)
小智 23
这些属性必须包含在textview标记中才能滚动.
其他一切都是可选的.
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="fill_parent"
android:ellipsize="marquee"
Run Code Online (Sandbox Code Playgroud)
小智 20
我遇到了同样的问题,这个讨论帮助了我,我只是替换了这一行
android:maxLines="1"
Run Code Online (Sandbox Code Playgroud)
用xml中的这一行
android:singleLine="true"
Run Code Online (Sandbox Code Playgroud)
它的作品txtView.setSelected(true);
也在我的活动中.
Shi*_*din 13
非常简单的工作代码:
用于无限滚动文本
<TextView
android:id="@+id/textView_News_HeadLine"
style="@style/black_extra_large_heading_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="8dp"
android:ellipsize="marquee"
android:marqueeRepeatLimit="-1"
android:singleLine="true"
android:text="HeadLine: Banglawash To be Continued" />
Run Code Online (Sandbox Code Playgroud)
你应该写下你的活动
textView.setSelected(true);
Run Code Online (Sandbox Code Playgroud)
<TextView
android:ellipsize="marquee"
android:singleLine="true"
.../>
Run Code Online (Sandbox Code Playgroud)
必须调用代码
textView.setSelected(true);
Run Code Online (Sandbox Code Playgroud)
我经历过textview marquee无效的情况.但请遵循这一点,我相信它会奏效.:)
<TextView
android:id="@+id/tv_marquee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:freezesText="true"
android:maxLines="1"
android:scrollHorizontally="true"
android:text="This is a sample code of marquee and it works"/>
Run Code Online (Sandbox Code Playgroud)
并以编程方式添加这两行...
tvMarquee.setHorizontallyScrolling(true);
tvMarquee.setSelected(true);
Run Code Online (Sandbox Code Playgroud)
如果视图中的任何一个已经被聚焦并且setSelected将使其工作,则需要tvMarquee.setSelected(true).无需使用.
android:singleLine="true"
Run Code Online (Sandbox Code Playgroud)
它已弃用且以上代码有效.
工作守则:
<TextView
android:id="@+id/scroller"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:text="Some veryyyyy long text with all the characters that cannot fit in screen, it so sad :( that I will not scroll"
android:textAppearance="?android:attr/textAppearanceLarge" />
Run Code Online (Sandbox Code Playgroud)
我正在使用minSDK = 14并且很好奇这些变化的集合是什么.我结束了:
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
Run Code Online (Sandbox Code Playgroud)
除了其他格式化的东西.我不需要scrollHoriontally,focusable或focusableInTouchMode.
这套确实需要打电话给
setSelected(true)
Run Code Online (Sandbox Code Playgroud)
据我所知,singleLine已被弃用,建议用maxLines = 1替换它.除非 - 当我这样做时,单独的更改会阻止文本滚动.人们希望当singleLine最终咬住灰尘时,maxLines会触发其当前的所有行为......
我遇到了同样的问题.Amith GC的答案(第一个答案被接受)是正确的,但有时是textview.setSelected(true); 当文本视图无法始终获得焦点时不起作用.因此,为了确保TextView Marquee正常工作,我不得不使用自定义TextView.
public class CustomTextView extends TextView {
public CustomTextView(Context context) {
super(context);
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if(focused)
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
@Override
public void onWindowFocusChanged(boolean focused) {
if(focused)
super.onWindowFocusChanged(focused);
}
@Override
public boolean isFocused() {
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用自定义TextView作为布局.xml文件中的滚动文本视图,如下所示:
<com.example.myapplication.CustomTextView
android:id="@+id/tvScrollingMessage"
android:text="@string/scrolling_message_main_wish_list"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/black"
android:gravity="center"
android:textColor="@color/white"
android:textSize="15dp"
android:freezesText="true"/>
Run Code Online (Sandbox Code Playgroud)
注意:在上面的代码片段中,com.example.myapplication是一个示例包名,应该用您自己的包名替换.
希望这会帮助你.干杯!
您必须将这些属性添加到选框
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
Run Code Online (Sandbox Code Playgroud)
并在活动类中添加这行代码
textView.setSelected(true)
Run Code Online (Sandbox Code Playgroud)
只需添加上述内容:
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
Run Code Online (Sandbox Code Playgroud)
和!!您必须在Java代码中使用TextView.setSelected(true).
如果你有一个带有EditText的输入表单(这是一个输入),那么你可以选择一个带有焦点和默认情况下在表单中选择的EditText.现在,如果你强制它通过TextView.setSelected(true),TextView最终会做任何选择.
因此,整个想法是使TextView小部件集中并选择以进行选框工作.
| 归档时间: |
|
| 查看次数: |
105754 次 |
| 最近记录: |