程序设计

专业和发烧友程序员的问答

4
如何以编程方式在相对布局中设置按钮的layout_align_parent_right属性?
我有一个以编程方式创建的相对布局: RelativeLayout layout = new RelativeLayout( this ); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); 现在,我要在此相对布局中添加两个按钮。但是问题是两个按钮都显示在RelatiiveLayout的左侧,彼此重叠。 buttonContainer.addView(btn1); buttonContainer.addView(btn2); 现在,我想知道如何像在xml中一样以编程方式设置按钮的android:layout_alignParentRight="true“或” android:layout_toLeftOf="@id/btn"属性?

13
例外:无法绑定到“ ngFor”,因为它不是已知的本机属性
我究竟做错了什么? import {bootstrap, Component} from 'angular2/angular2' @Component({ selector: 'conf-talks', template: `<div *ngFor="talk of talks"> {{talk.title}} by {{talk.speaker}} <p>{{talk.description}} </div>` }) class ConfTalks { talks = [ {title: 't1', speaker: 'Brian', description: 'talk 1'}, {title: 't2', speaker: 'Julie', description: 'talk 2'}]; } @Component({ selector: 'my-app', directives: [ConfTalks], template: '<conf-talks></conf-talks>' }) class …

11
Matplotlib图:删除轴,图例和空白
我是Python和Matplotlib的新手,我想简单地将colormap应用于图像并写入结果图像,而无需使用轴,标签,标题或通常由matplotlib自动添加的任何内容。这是我所做的: def make_image(inputname,outputname): data = mpimg.imread(inputname)[:,:,0] fig = plt.imshow(data) fig.set_cmap('hot') fig.axes.get_xaxis().set_visible(False) fig.axes.get_yaxis().set_visible(False) plt.savefig(outputname) 它成功删除了图形的轴,但是保存的图形在实际图像周围显示了白色填充和边框。如何删除它们(至少是白色填充)?谢谢
285 python  matplotlib 

6
如何在Emacs中用换行符替换字符?
我正在尝试;使用replace-string和/或replace-regexp在Emacs 中用新行替换字符(例如)。 我尝试了以下命令: M-x replace-string RET ; RET \n 这将替换;为2个字符:\n。 M-x replace-regex RET ; RET \n 这将导致以下错误(显示在迷你缓冲区中): 替换文字中无效的使用\。 使用replace-string此任务有什么问题?还有其他方法吗? 谢谢。
285 emacs  replace 

13
通过Javascript中的引用传递变量
如何在JavaScript中通过引用传递变量?我想对3个变量执行几个操作,因此我想将它们放在for循环中并对每个变量执行操作。 伪代码: myArray = new Array(var1, var2, var3); for (var x = 0; x < myArray.length; x++){ //do stuff to the array makePretty(myArray[x]); } //now do stuff to the updated vars 做这个的最好方式是什么?

2
使用自定义类类型作为键的C ++ unordered_map
我正在尝试使用自定义类作为的键unordered_map,如下所示: #include <iostream> #include <algorithm> #include <unordered_map> using namespace std; class node; class Solution; class Node { public: int a; int b; int c; Node(){} Node(vector<int> v) { sort(v.begin(), v.end()); a = v[0]; b = v[1]; c = v[2]; } bool operator==(Node i) { if ( i.a==this->a && i.b==this->b &&i.c==this->c …

15
用Python发送100,000个HTTP请求的最快方法是什么?
我正在打开一个具有100,000个URL的文件。我需要向每个URL发送一个HTTP请求并打印状态代码。我正在使用Python 2.6,到目前为止,我们研究了Python实现线程/并发性的许多令人困惑的方式。我什至看过python 并发库,但无法弄清楚如何正确编写此程序。有没有人遇到过类似的问题?我想通常我需要知道如何尽快地在Python中执行数千个任务-我想这意味着“同时”。
285 python  http  concurrency 


20
CSS3 100vh在移动浏览器中不是恒定的
我有一个非常奇怪的问题……在每个浏览器和移动版本中,我都遇到以下问题: 加载页面时,所有浏览器都有一个顶部菜单(例如,显示地址栏),当您开始滚动页面时,该菜单会向上滑动。 有时仅在视口的可见部分计算100vh ,因此当浏览器栏向上滑动时100vh会增加(以像素为单位) 由于尺寸已更改,所有布局都会重新绘制和重新调整 对用户体验的不良影响 如何避免这个问题?当我第一次听说viewport-height时,我很兴奋,我以为可以将其用于固定高度块而不是使用javascript,但是现在我认为唯一的方法实际上是带有一些resize事件的javascript ... 您可以在以下示例中看到问题: 谁能帮我/建议CSS解决方案? 简单的测试代码: 显示代码段 /* maybe i can track the issue whe it occours... */ $(function(){ var resized = -1; $(window).resize(function(){ $('#currenth').val( $('.vhbox').eq(1).height() ); if (++resized) $('#currenth').css('background:#00c'); }) .resize(); }) *{ margin:0; padding:0; } /* this is the box which should keep …
285 html  css  viewport-units 

7
在TextView中以编程方式设置左可绘制
我在xml中有一个textView。 <TextView android:id="@+id/bookTitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:drawableLeft="@drawable/checkmark" android:gravity="center_vertical" android:textStyle="bold" android:textSize="24dip" android:maxLines="1" android:ellipsize="end"/> 如您所见,我在xml中设置了DrawableLeft。 我想更改代码中的drawable。 无论如何要这样做吗?还是在代码中为文本视图设置drawableLeft?

17
“ x = x ++”之后的x是什么?
执行此操作后(幕后)会发生什么? int x = 7; x = x++; 也就是说,何时在一个语句中对变量进行后递增并分配给自己?我编译并执行了这个。即使整个陈述之后x仍然是7 。在我的书中,它说是递增的!x

12
SVN是否仍然存在冲突?
如何使该目录摆脱冲突?我不在乎是否使用“他们的”或“我的”或任何其他方式解决了... PS C:\Users\Mark\Desktop\myproject> svn ci -m "gr" svn: Commit failed (details follow): svn: Aborting commit: 'C:\Users\Mark\Desktop\myproject\addons' remains in conflict PS C:\Users\Mark\Desktop\myproject> svn resolve --accept working C:\Users\Mark\Desktop\myproject\addons Resolved conflicted state of 'C:\Users\Mark\Desktop\myproject\addons' PS C:\Users\Mark\Desktop\myproject> svn ci -m "grr" svn: Commit failed (details follow): svn: Commit item 'addons' has copy flag but …
284 svn 

10
为什么instanceof对某些文字返回false?
"foo" instanceof String //=> false "foo" instanceof Object //=> false true instanceof Boolean //=> false true instanceof Object //=> false false instanceof Boolean //=> false false instanceof Object //=> false // the tests against Object really don't make sense 数组文字和对象文字匹配... [0,1] instanceof Array //=> true {0:1} instanceof Object //=> true …

16
如何修复“ ImportError:无法导入名称IncompleteRead”?
当我尝试使用pip或安装任何内容时pip3,我得到: $ sudo pip3 install python3-tk Traceback (most recent call last): File "/usr/bin/pip3", line 9, in <module> load_entry_point('pip==1.5.6', 'console_scripts', 'pip3')() File "/usr/lib/python3/dist-packages/pkg_resources.py", line 356, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/usr/lib/python3/dist-packages/pkg_resources.py", line 2476, in load_entry_point return ep.load() File "/usr/lib/python3/dist-packages/pkg_resources.py", line 2190, in load ['__name__']) File "/usr/lib/python3/dist-packages/pip/__init__.py", line 61, in <module> …
284 python  pip 

20
AWS ssh访问“权限被拒绝(公钥)”问题[关闭]
关闭。此问题不符合堆栈溢出准则。它当前不接受答案。 想改善这个问题吗?更新问题,使其成为Stack Overflow 的主题。 4年前关闭。 改善这个问题 如何通过ssh连接到AWS实例? 我有: 在AWS上注册; 在AWS网站上创建了公钥和证书,并将它们保存到磁盘; 进入我的控制台并创建环境变量: $ export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/ $ export EC2_CERT=/home/default/aws/cert-EBAINCRNWHDSCWWIHSOKON2YWGJZ5LSQ.pem $ export EC2_PRIVATE_KEY=/home/default/aws/pk-EBAINCRNWHDSCWWIHSOKON2YWGJZ5LSQ.pem 告知AWS API使用此密钥对并将密钥对保存到文件中: $ ec2-add-keypair ec2-keypair > ec2-keypair.pem 使用以下密钥对启动一个AWS Ubuntu 9实例: $ ec2-run-instances ami-ed46a784 -k ec2-keypair 尝试建立与实例的ssh连接: $ ssh -v -i ec2-keypair.pem ubuntu@ec2-174-129-185-190.compute-1.amazonaws.com OpenSSH_5.1p1 Debian-5ubuntu1, OpenSSL 0.9.8g 19 Oct 2007 debug1: …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.