首页 \ 问答 \ TextView Scrollable(TextView Scrollable)

TextView Scrollable(TextView Scrollable)

我将TextView设置为可滚动:

textView.setMovementMethod(new ScrollingMovementMethod());

但是,当我更新我的TextView的文本时,滚动位置保持在最后的文本位置,导致有时文本变得不可见,然后,我需要移动滚动以查看新文本(我更新:textView.setText (newText))。

我尝试了这些代码,但没有发现任何变化:

textView.invalidate(); 
textView.requestLayout(); 

textView.scrollBy(0, 0)
textView.scrollTo(0, 0);

PS:textView是RelativeLayout的子节点。


I set my TextView to be scrollable:

textView.setMovementMethod(new ScrollingMovementMethod());

But, when I update my TextView's texts, the scrolling position keeps at the last text position, resulting in, sometimes, the text getting invisible and then, I need to move the scroll to see the new text (I update with: textView.setText(newText)).

I tried those codes, but no changes were noted:

textView.invalidate(); 
textView.requestLayout(); 

textView.scrollBy(0, 0)
textView.scrollTo(0, 0);

P.S.: the textView is a child of a RelativeLayout.


原文:https://stackoverflow.com/questions/21028222
更新时间:2023-12-03 17:12

最满意答案

import csv
import numpy as np
from scipy.stats import norm, lognorm
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from matplotlib.widgets import Slider, Button, RadioButtons



#####Importing Data from csv file#####

dataset1 = np.genfromtxt('dataSet1.csv', dtype = float, delimiter = ',', skip_header = 1, names = ['a', 'b', 'c', 'x0'])
dataset2 = np.genfromtxt('dataSet2.csv', dtype = float, delimiter = ',', skip_header = 1, names = ['a', 'b', 'c', 'x0'])
dataset3 = np.genfromtxt('dataSet3.csv', dtype = float, delimiter = ',', skip_header = 1, names = ['a', 'b', 'c', 'x0'])

#####_____#####



#####Creating Subplots#####

fig = plt.figure()
plt.subplots_adjust(left=0.15, bottom=0.1)

ax1 = fig.add_subplot(321)                                                  #Subplot 1
ax1.set_xlabel('a', fontsize = 14)
#ax1.set_ylabel('PDF', fontsize = 14)
##ax1.set_title('Probability Density Function', fontsize = 10)
##ax1.text(-2, 0.4, r'$\mu=0,\ \sigma^2=1$')
ax1.grid(True)

ax2 = fig.add_subplot(323)                                                  #Subplot 2
ax2.set_xlabel('b', fontsize = 14)
#ax2.set_ylabel('PDF', fontsize = 14)
##ax2.set_title('Probability Density Function', fontsize = 10)
##ax2.text(-2, 0.4, r'$\mu=0,\ \sigma^2=1$')
ax2.grid(True)

ax3 = fig.add_subplot(325)                                                  #Subplot 3
ax3.set_xlabel('c', fontsize = 14)
#ax3.set_ylabel('PDF', fontsize = 14)
##ax3.set_title('Probability Density Function', fontsize = 10)
##ax3.text(-2, 0.4, r'$\mu=0,\ \sigma^2=1$')
ax3.grid(True)

ax4 = fig.add_subplot(122)                                                  #Subplot 4
ax4.set_xlabel('x0', fontsize = 14)
ax4.set_ylabel('PDF', fontsize = 14)
##ax4.set_title('Probability Density Function', fontsize = 10)
##ax4.text(-2, 0.4, r'$\mu=0,\ \sigma^2=1$')
ax4.grid(True)

#####_____#####



#####Plotting Distributions#####

ax1.hist(dataset1['a'], bins=50, color = 'red',alpha = 0.5, normed = True)
ax2.hist(dataset1['b'], bins=50, color = 'red',alpha = 0.5, normed = True)
ax3.hist(dataset1['c'], bins=50, color = 'red',alpha = 0.5, normed = True)
ax4.hist(dataset1['x0'], bins=50, color = 'red',alpha = 0.5, normed = True)

#####_____#####



#######Creating Radio Button#####

axcolor = 'lightgoldenrodyellow'
rax = plt.axes([0.03, 0.48, 0.06, 0.09], axisbg=axcolor)
radio = RadioButtons(rax, ('Data Set1', 'Data Set2', 'Data Set3'))

#####_____#####



#####Updating Radio Button#####

radio_label = 'Data Set1'
func = {'Data Set1': dataset1, 'Data Set2': dataset2, 'Data Set3': dataset3}
axcl = {'Data Set1': 'red', 'Data Set2': 'blue', 'Data Set3': 'green'}

def update_radio(label):
    global radio_label             #so we can overwrite the variable defined above and not create a local one
    radio_label = label
    print(radio_label)
    ax1.clear()
    ax2.clear()
    ax3.clear()
    ax4.clear()
    ax1.hist(func[radio_label]['a'], bins=50, color = 'red',alpha = 0.5)
    ax2.hist(func[radio_label]['b'], bins=50, color = 'red',alpha = 0.5)
    ax3.hist(func[radio_label]['c'], bins=50, color = 'red',alpha = 0.5)
    ax4.hist(func[radio_label]['x0'], bins=50, color = 'red',alpha = 0.5)
    ax1.grid(True)
    ax2.grid(True)
    ax3.grid(True)
    ax4.grid(True)


    plt.draw()



radio.on_clicked(update_radio)

#####_____#####




plt.show()

import csv
import numpy as np
from scipy.stats import norm, lognorm
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from matplotlib.widgets import Slider, Button, RadioButtons



#####Importing Data from csv file#####

dataset1 = np.genfromtxt('dataSet1.csv', dtype = float, delimiter = ',', skip_header = 1, names = ['a', 'b', 'c', 'x0'])
dataset2 = np.genfromtxt('dataSet2.csv', dtype = float, delimiter = ',', skip_header = 1, names = ['a', 'b', 'c', 'x0'])
dataset3 = np.genfromtxt('dataSet3.csv', dtype = float, delimiter = ',', skip_header = 1, names = ['a', 'b', 'c', 'x0'])

#####_____#####



#####Creating Subplots#####

fig = plt.figure()
plt.subplots_adjust(left=0.15, bottom=0.1)

ax1 = fig.add_subplot(321)                                                  #Subplot 1
ax1.set_xlabel('a', fontsize = 14)
#ax1.set_ylabel('PDF', fontsize = 14)
##ax1.set_title('Probability Density Function', fontsize = 10)
##ax1.text(-2, 0.4, r'$\mu=0,\ \sigma^2=1$')
ax1.grid(True)

ax2 = fig.add_subplot(323)                                                  #Subplot 2
ax2.set_xlabel('b', fontsize = 14)
#ax2.set_ylabel('PDF', fontsize = 14)
##ax2.set_title('Probability Density Function', fontsize = 10)
##ax2.text(-2, 0.4, r'$\mu=0,\ \sigma^2=1$')
ax2.grid(True)

ax3 = fig.add_subplot(325)                                                  #Subplot 3
ax3.set_xlabel('c', fontsize = 14)
#ax3.set_ylabel('PDF', fontsize = 14)
##ax3.set_title('Probability Density Function', fontsize = 10)
##ax3.text(-2, 0.4, r'$\mu=0,\ \sigma^2=1$')
ax3.grid(True)

ax4 = fig.add_subplot(122)                                                  #Subplot 4
ax4.set_xlabel('x0', fontsize = 14)
ax4.set_ylabel('PDF', fontsize = 14)
##ax4.set_title('Probability Density Function', fontsize = 10)
##ax4.text(-2, 0.4, r'$\mu=0,\ \sigma^2=1$')
ax4.grid(True)

#####_____#####



#####Plotting Distributions#####

ax1.hist(dataset1['a'], bins=50, color = 'red',alpha = 0.5, normed = True)
ax2.hist(dataset1['b'], bins=50, color = 'red',alpha = 0.5, normed = True)
ax3.hist(dataset1['c'], bins=50, color = 'red',alpha = 0.5, normed = True)
ax4.hist(dataset1['x0'], bins=50, color = 'red',alpha = 0.5, normed = True)

#####_____#####



#######Creating Radio Button#####

axcolor = 'lightgoldenrodyellow'
rax = plt.axes([0.03, 0.48, 0.06, 0.09], axisbg=axcolor)
radio = RadioButtons(rax, ('Data Set1', 'Data Set2', 'Data Set3'))

#####_____#####



#####Updating Radio Button#####

radio_label = 'Data Set1'
func = {'Data Set1': dataset1, 'Data Set2': dataset2, 'Data Set3': dataset3}
axcl = {'Data Set1': 'red', 'Data Set2': 'blue', 'Data Set3': 'green'}

def update_radio(label):
    global radio_label             #so we can overwrite the variable defined above and not create a local one
    radio_label = label
    print(radio_label)
    ax1.clear()
    ax2.clear()
    ax3.clear()
    ax4.clear()
    ax1.hist(func[radio_label]['a'], bins=50, color = 'red',alpha = 0.5)
    ax2.hist(func[radio_label]['b'], bins=50, color = 'red',alpha = 0.5)
    ax3.hist(func[radio_label]['c'], bins=50, color = 'red',alpha = 0.5)
    ax4.hist(func[radio_label]['x0'], bins=50, color = 'red',alpha = 0.5)
    ax1.grid(True)
    ax2.grid(True)
    ax3.grid(True)
    ax4.grid(True)


    plt.draw()



radio.on_clicked(update_radio)

#####_____#####




plt.show()

相关问答

更多
  • 这比我预想的要容易,我只是这样做了: pylab.subplot(4,4,10) ,它工作。 It was easier than I expected, I just did: pylab.subplot(4,4,10) and it worked.
  • 如果figure是一个Figure实例,你可以通过它获取其中的轴 allaxes = fig.get_axes() 这个( allaxes )的返回是图中所有轴的列表。 在此列表中,您需要从图中或其他来源了解哪个子图。 If figure is a Figure instance you can get the axes inside it via allaxes = fig.get_axes() The return of this (allaxes) is a list of all the axe ...
  • 您可以使用colspan当您使用suplot2grid而不是子图。 import matplotlib.pyplot as plt ax1 = plt.subplot2grid(shape=(2,6), loc=(0,0), colspan=2) ax2 = plt.subplot2grid((2,6), (0,2), colspan=2) ax3 = plt.subplot2grid((2,6), (0,4), colspan=2) ax4 = plt.subplot2grid((2,6), (1,1) ...
  • _subplots是axes的子模块: https : //github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes/_subplots.py 它不应被操纵,正如其领先的下划线所暗示的那样。 看一下源代码,我猜你的AxesSubplot是一个用subplot_class_factory创建的类。 _subplots is a submodule of axes: https://github.com/matplotlib/matplot ...
  • 当我将其保存为.png文件时,我得到了更好的数字。 fig = plt.figure(figsize=(20, 222)) plt.subplots_adjust(top=.9, bottom=0.1, wspace=0.2, hspace=0.2) for i in range(1, 65): print 'E', i, ':' plt.subplot(64, 2, i) plt.ylabel('E%s' % str(i)) i += 1 print E[0 ...
  • plt.*设置通常适用于matplotlib的当前图; 与plt.subplot ,你开始一个新的情节,因此设置不再适用于它。 你可以通过与图表相关联的Axes对象( 见这里的例子 )共享标签,蜱等,但是恕我直言,这会在这里矫枉过正。 相反,我会建议将常用的“样式”放入一个函数中,并根据每个图表调用它: def applyPlotStyle(): plt.xlabel('Size') plt.ylabel('Time(s)'); plt.title('Matrix multiplic ...
  • import csv import numpy as np from scipy.stats import norm, lognorm import matplotlib.pyplot as plt import matplotlib.mlab as mlab from matplotlib.widgets import Slider, Button, RadioButtons #####Importing Data from csv file##### dataset1 = np.genfromt ...
  • plt.subplot返回一个子对象,它是一种plt.subplot对象。 它有两种添加轴标签的方法: set_xlabel和set_ylabel : ax = plt.subplot('111') ax.set_xlabel('X Axis') ax.set_ylabel('Y Axis') 您也可以调用plt.xlabel和plt.ylabel (就像您以前所做的那样),并指定要将标签应用到的轴。 ax = plt.subplot('111') plt.xlabel('X Axis', axes=ax ...
  • 当然,只要你重新定位它们后你就不会使用tight_layout (因此也tight_layout )(之前你可以安全地使用它)。 基本上,只需执行以下操作: import matplotlib.pyplot as plt # Create something similar to your pickled figure...... fig, (ax1, ax2) = plt.subplots(ncols=2) ax1.plot(range(10), 'r^-') ax1.set(title='Origin ...
  • 由于链接问题中的注释( Matplotlib中两个图之间的绘制线 )表明,您应该使用ConnectionPatch连接图。 这个ConnectionPatch的好处不仅在于它易于实现,而且还可以与数据一起移动和缩放。 以下是如何使用它的示例。 import matplotlib.pyplot as plt from matplotlib.patches import ConnectionPatch import numpy as np fig, (ax1, ax2) = plt.subplots(1,2, ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)