
这是我的MainActivity.Java中的代码:
seek_bar = (Seekbar)findVIEwByID(R.ID.seekbar); text_vIEw =(TextVIEw)findVIEwByID(R.ID.textVIEw); seek_bar.setonSeekbarchangelistener( new Seekbar.OnSeekbarchangelistener() { int progress_value; @OverrIDe public voID onProgressChanged(Seekbar seekbar,int progress,boolean fromUser) { progress_value = progress; TextVIEw newtext = (TextVIEw) findVIEwByID(R.ID.textVIEw2); ScrollVIEw hscrollVIEwMain = (ScrollVIEw)findVIEwByID(R.ID.scrollVIEv); newtext.setText(hscrollVIEwMain.getMaxScrollAmount().toString()); // I made this because I thought that it would tell me the maximum amount of pixels in my text but toString() doesnt work somehow. It is redlined :( hscrollVIEwMain.scrollTo(0,(hscrollVIEwMain.getMaxScrollAmount()/100)*progress_value); //this scrolls only little when seekbar is moved } 这是我的activity_main.xml
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:tools="http://schemas.androID.com/tools"androID:layout_wIDth="match_parent"androID:layout_height="match_parent"androID:orIEntation="vertical"tools:context=".MainActivity"androID:weightSum="1"><Seekbar androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:ID="@+ID/seekbar" /><ScrollVIEw androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:ID="@+ID/scrollVIEv" androID:layout_gravity="center_horizontal" androID:fillVIEwport="false" androID:clickable="false" androID:nestedScrollingEnabled="false" androID:isScrollContainer="false"> <linearLayout androID:ID="@+ID/linearLayout" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="vertical"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="@string/testtext" androID:ID="@+ID/textVIEw2" /> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:ID="@+ID/textVIEw" androID:text="@string/maintext" /></linearLayout></ScrollVIEw></linearLayout>
我还想过使用computeVerticalScrollRange()方法而不是getMaxScrollAmount,但因为它是受保护的方法,我不知道如何使用它.我非常喜欢这里所以任何帮助将非常感激.
解决方法 在我的意见中你可以这样做:1)在Seekbar的左/右创建一个@R_502_4614@layout
2)在这个@R_502_4614@Layout中创建一个TextVIEw
3)现在你必须得到@R_502_4614@Layout的高度.要做到这一点,你可以使用onMeasure / onLayout(但这样你必须实现自定义@R_502_4614@Layout)或只是一个VIEwTreeObserver
4)现在您拥有两个组件的高度,以便进行计算
5)每次移动Seekbar时,都必须“更新”TextVIEw位置.在@R_502_4614@Layout内部,您可以使用children.layout(左,上,右,下)设置位置,然后在TextVIEw上调用invalIDate()来更新它.
希望能帮助到你
总结以上是内存溢出为你收集整理的android – 如何使用搜索栏滚动文本?全部内容,希望文章能够帮你解决android – 如何使用搜索栏滚动文本?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)