linearLayout当我按下按钮时,我有一个消失,当我再次按下按钮时它会回来.但它做得如此之快,看起来并不好看.我这样做是通过:
disappearView.setVisibility(View.GONE);
Run Code Online (Sandbox Code Playgroud)
我想添加一些动画......如果我只是将visibity设置为隐藏布局所在的空间仍然存在.所以我尝试了这个:
if (disappearView.getVisibility() == View.VISIBLE){
Animation out = AnimationUtils.makeOutAnimation(this, true);
disappearView.startAnimation(out);
disappearView.setVisibility(View.INVISIBLE);
disappearView.setVisibility(View.GONE);
}
else {
Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
disappearView.startAnimation(in);
disappearView.setVisibility(View.VISIBLE);
}
Run Code Online (Sandbox Code Playgroud)
这会使动画太快而消失.你根本看不到它.gone在invisible设置...或延迟后我是否需要使用线程启动?或者有更好的方法来做这一切吗?
目前我正在检查以下字符串:
if(parseCommand.contains("vlan1")
|| parseCommand.contains("Fa0/1i") || parseCommand.contains("Fa0/1o")
|| parseCommand.contains("Fa1/0") || parseCommand.contains("Fa1/1")
|| parseCommand.contains("Fa1/2") || parseCommand.contains("Fa1/3")
|| parseCommand.contains("Fa1/4") || parseCommand.contains("Fa1/5")
|| parseCommand.contains("Fa1/6") || parseCommand.contains("Fa1/7")
|| parseCommand.contains("Fa1/8") || parseCommand.contains("Fa1/9")
|| parseCommand.contains("Fa1/11") || parseCommand.contains("Gi0"))
{
//do things here
}
Run Code Online (Sandbox Code Playgroud)
但是它可能包含vlan1到vlan4094,我必须检查这些.最简单的方法是什么,我是否必须将它全部放在for循环中,增加到4094我猜?
for (int i = 1; i <= 4094; i++)
{
if(parseCommand.contains("vlan"[i]))
{
//do stuff here
}
}
if(other conditions from above)
{
//do same stuff again here
}
Run Code Online (Sandbox Code Playgroud)
或者我可以在for循环中坚持所有条件,并在那里做所有事情.这一切看起来都很混乱,是否有一种非混乱的方式呢?
我的应用程序由一项活动组成。当我按下时没有任何反应,这是为什么?我认为它会杀死应用程序。如果我按回家,应用程序会根据需要在后台运行。它只是后退按钮什么也不做。我能做些什么来影响这一点?
我已阅读文档:
public void onBackPressed ()
Run Code Online (Sandbox Code Playgroud)
当活动检测到用户按下后退键时调用。默认实现只是完成当前活动,但您可以覆盖它以执行您想要的任何操作。
我没有覆盖这一点。
这是已经提到的内容,覆盖键:
public boolean dispatchKeyEvent(KeyEvent event) {
if (event == null || event.getAction() == KeyEvent.ACTION_UP) {
return false;
}
if(event.getKeyCode() == KeyEvent.KEYCODE_DEL){
mEntry.setOnFocusChangeListener(new OnFocusChangeListener(){
@Override
public void onFocusChange(View v,boolean hasFocus){
/* When focus is lost check that the text field
* has valid values.
*/
if (!hasFocus && !mEntry.getText().toString().trim().equals("")) {
mSession.appendToEmulator(cmdLeft, 0, cmdLeft.length);
mSession.appendToEmulator(cmdErase, 0, cmdErase.length);
Log.d(TAG, "in inner delete");
}
else {mEntry.setText(" ");
}
}
});
Log.d(TAG, "in …Run Code Online (Sandbox Code Playgroud) 我有一个band1如下所示的字典,我想根据字典中每个列表的第一个和最后一个元素打印出一个图表.x轴上每个列表的第一个元素是频率,最后一个元素是接收强度,应该在y轴上.例如,10812的强度为16等
band1 = {'channel1': [10564, 2112.8, 1922.8, 0],
'channel10': [10787, 2157.4, 1967.4, 11],
'channel11': [10812, 2162.4, 1972.4, 16],
'channel12': [10837, 2167.4, 1977.4, 46],
'channel2': [10589, 2117.8, 1927.8, 29],
'channel3': [10612, 2122.4, 1932.4, 0],
'channel4': [10637, 2127.4, 1937.4, 40],
'channel5': [10662, 2132.4, 1942.4, 54],
'channel6': [10687, 2137.4, 1947.4, 0],
'channel7': [10712, 2142.4, 1952.4, 50],
'channel8': [10737, 2147.4, 1957.4, 19],
'channel9': [10762, 2152.4, 1962.4, 24]}
Run Code Online (Sandbox Code Playgroud)
我没有问题排序这个,channel1 - > channel12但是有什么好方法可以打印一个漂亮的图表,字典中的条目数量可以随着或多或少的频道而变化.
我有这样的代码:
else if (v == mSettings)
{
if (disappearView.getVisibility() == View.VISIBLE)
{
AlphaAnimation fadeOutAnimation = new AlphaAnimation(1, 0); // start alpha, end alpha
fadeOutAnimation.setDuration(1000); // time for animation in milliseconds
fadeOutAnimation.setFillAfter(true); // make the transformation persist
Animation out = AnimationUtils.makeOutAnimation(this, true);
disappearView.startAnimation(out);
disappearView.setVisibility(View.INVISIBLE);
out.setAnimationListener(new Animation.AnimationListener()
{
public void onAnimationEnd(Animation animation)
{
disappearView.setVisibility(View.GONE);
Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
bannerView.startAnimation(in);
bannerView.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) { }
@Override
public void onAnimationStart(Animation animation) { }
});
}
else {
Animation in …Run Code Online (Sandbox Code Playgroud) 我正在搜索一个字符串,会有一行以ssid开头,我需要在那之后直接找到这个单词.所以一个例子是"ssid home",家就是我希望回归的词.我是以迂回的方式做到这一点,看起来非常凌乱,我应该怎样做这个,一个正则表达式或者是否有办法整理我所做的事情?
a = """
!
interface blah
a
ssid test
v
v
"""
b = a.split("\n")
matches = [x for x in b if "ssid" in x]
matches = [i.split() for i in matches]
print matches[0][1]
Run Code Online (Sandbox Code Playgroud) 我有一本字典,如下图所示.
band1= {'channel1': 10564, 'channel2': 10589, 'channel3': 10612, 'channel4': 10637,'channel5': 10662, 'channel6': 10687,
'channel7': 10712, 'channel8': 10737, 'channel9': 10762, 'channel10': 10787,'channel11': 10812, 'channel12': 10837, }
Run Code Online (Sandbox Code Playgroud)
我想要一个编辑这本词典的好方法.对于每个条目,我希望添加的另一个值是值/ 5,输入的第三个值是值/ 5-190
然后字典看起来像(表达式实际转换为它们的最终值):
band1= {'channel1': [10564, 10564/5, 10564/5-190], 'channel2': [10589,10589/5,10589/5-190], 'channel3': [10612,10612/5,10612/5-190], 'channel4': [10637,10637/5,10637/5-190],
'channel5': [10662,10662/5,10662/5-190], 'channel6': [10687,10687/5,10687/5-190],
'channel7': [10712, 10712/5, 10712/5-190], 'channel8': [10737,10737/5,10737/5-190], 'channel9': [10762,10762/5,10762/5-190], 'channel10': [10787,10787/5,10787/5-190],'channel11': [10812,10812/5,10812/5-190], 'channel12': [10837,10837/5,10837/5-190]}
Run Code Online (Sandbox Code Playgroud)
我必须使用大量条目来执行此操作,因此如果我可以以pythonic方式添加它们,那么最好只输入它们.另外5或190对于其他字典也是可变的,因此能够容易地改变它是很好的,这是不硬编码的另一个原因.例如,另一个字典可能具有我需要除以4的规则并且为第二个元素添加200,然后对于第三个元素我可能必须添加另一个变量数.
band2= {'channel1': [10564, 10564/4+200, 10564/4+200+100]
Run Code Online (Sandbox Code Playgroud) 我想解析ifconfig,以便我只留下分配了IP地址的vlan.我想要来自每个vlan的以下数据,接口名称,IP地址和mac地址(转换格式的mac).这些应存储在列表列表中.每个vlan的列表.
到目前为止,我刚刚为每个vlan创建了一个包含IP和接口名称的列表.但是,我觉得我会偏离轨道并以不好的方式做这件事,有什么建议吗?
期望的输出:
[['vlan1', '192.168.2.2', '0013.F200.0058'], ['vlan100', '192.168.110.2','0013.F200.0058'], ['vlan20', '192.168.30.2','0013.F200.0058']]
Run Code Online (Sandbox Code Playgroud)
当前输出:
['vlan1', '0013.F200.0058', '192.168.2.2', 'vlan100', '0013.F200.0058', '192.168.110.2', 'vlan20', '0013.F200.0058', '192.168.30.2']
Run Code Online (Sandbox Code Playgroud)
我知道我可以轻松地将这个平面列表转换为嵌套列表,但我觉得应该在此之前的步骤中完成.
EG但我觉得这很糟糕:
i=0
new_list=[]
while i<len(data_list):
new_list.append(data_list[i:i+3])
i+=3
Run Code Online (Sandbox Code Playgroud)
码:
import re
a = """
vlan1 Link encap:Ethernet HWaddr 00:13:F2:00:00:58
inet addr:192.168.2.2 Bcast:192.168.2.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:39 errors:0 dropped:0 overruns:0 frame:0
TX packets:2708 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2188 (2.1 KiB) TX bytes:383156 (374.1 KiB)
vlan100 Link encap:Ethernet HWaddr 00:13:F2:00:00:58
inet addr:192.168.110.2 Bcast:192.168.110.255 Mask:255.255.255.0 …Run Code Online (Sandbox Code Playgroud) 在python中学习类.我想要两个字符串之间的区别,一种减法.例如:
a = "abcdef"
b ="abcde"
c = a - b
Run Code Online (Sandbox Code Playgroud)
这将给出输出f.
我正在看这个课程,我是新手,所以想要澄清它是如何工作的.
class MyStr(str):
def __init__(self, val):
return str.__init__(self, val)
def __sub__(self, other):
if self.count(other) > 0:
return self.replace(other, '', 1)
else:
return self
Run Code Online (Sandbox Code Playgroud)
这将按以下方式工作:
>>> a = MyStr('thethethethethe')
>>> b = a - 'the'
>>> a
'thethethethethe'
>>> b
'thethethethe'
>>> b = a - 2 * 'the'
>>> b
'thethethe'
Run Code Online (Sandbox Code Playgroud)
因此,将字符串传递给类并调用构造函数__init__.这运行构造函数并返回一个对象,其中包含字符串的值?然后创建一个新的减法函数,这样当你使用-MyStr对象时,它只是定义了减法如何与该类一起工作?当使用字符串调用sub时,count用于检查该字符串是否是创建的对象的子字符串.如果是这种情况,则会删除第一次出现的传递字符串.这种理解是否正确?
编辑:基本上这个类可以简化为:
class MyStr(str):
def __sub__(self, other):
return self.replace(other, '', 1)
Run Code Online (Sandbox Code Playgroud) 我有一个如下所示的列表:
a = ['e8:04:62:23:57:d0\t2462\t-55\t[WPA2-PSK-CCMP][ESS]\tTest', '00:1b:2f:48:8b:f2\t2462\t-57\t[WPA2-PSK-CCMP-preauth][ESS]\tT_test', 'e8:04:62:23:4e:70\t2437\t-61\t[WPA2-PSK-CCMP][ESS]\tT_guest', 'e8:04:62:23:57:d1\t2462\t-53\t[ESS]\t', 'e8:04:62:23:4e:71\t2437\t-56\t[ESS]\t']
Run Code Online (Sandbox Code Playgroud)
我想根据每个元素的第三个选项卡后的数字对列表进行排序,因此在这种情况下,-55、-57、-61、-53 应将列表顺序更改为 -53、-55、-57、-61。我尝试过的任何方式似乎都非常复杂(制作列表等)。我应该使用正则表达式/模式来简化吗?