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 ...
-
如何让Matplotlib中的单选按钮一起更新4个子图?(How can I get the radio button in Matplotlib to update 4 subplots together?)[2023-09-20]
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 ...
-
Matplotlib:重新排序子图(Matplotlib: reorder subplots)[2022-08-14]
当然,只要你重新定位它们后你就不会使用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处理缩放时绘制两个子图之间的线(Plot a line between two subplots while handling the zoom with Matplotlib)[2022-03-06]
由于链接问题中的注释( Matplotlib中两个图之间的绘制线 )表明,您应该使用ConnectionPatch连接图。 这个ConnectionPatch的好处不仅在于它易于实现,而且还可以与数据一起移动和缩放。 以下是如何使用它的示例。 import matplotlib.pyplot as plt from matplotlib.patches import ConnectionPatch import numpy as np fig, (ax1, ax2) = plt.subplots(1,2, ...