有时,我觉得方法超载可能会造成混乱.
class a {
public:
void copy(float f);
void copy(double d);
};
Run Code Online (Sandbox Code Playgroud)
a me;
me.copy(1.2); // Not obvious at the first sight on which version we are calling.
Run Code Online (Sandbox Code Playgroud)
对此的解决方法是.
class a {
public:
void copyFloat(float f);
void copyDouble(double d);
};
Run Code Online (Sandbox Code Playgroud)
但是,拥有不同名称的方法,执行相同的功能似乎也不是一个好主意.我可以知道,您考虑什么,在方法重载或具有不同命名的方法中进行选择?
在设计公共API时,将构造函数设置为显式是一种好的做法吗?
class A {
public:
//explicit A(int i){}
A(int i){}
};
void fun(const A& a) {}
int main() {
// If I use explicit for A constructor, I can prevent this mistake.
// (Or shall I call it as feature?)
fun(10);
}
Run Code Online (Sandbox Code Playgroud)
或者我应该允许隐式转换,以允许用户以较少的输入调用我的API?
我认为ADT应该带有一个用于构建GUI的可视化编辑器:构建Android UI的简便方法?
但是,我只是找不到它.我想知道带有ADT插件的Eclipse Visual Editor在哪里.
我可以毫无问题地运行HelloWorld应用程序.但是,每当我点击main.xml左侧导航树布局文件夹时,这就是我得到的.我希望得到的是一个WYSIWYG编辑器.

我想将一个char指针数组传递给C函数.
我指的是http://docs.python.org/library/ctypes.html#arrays
我写下面的代码.
from ctypes import *
names = c_char_p * 4
# A 3 times for loop will be written here.
# The last array will assign to a null pointer.
# So that C function knows where is the end of the array.
names[0] = c_char_p('hello')
Run Code Online (Sandbox Code Playgroud)
我收到以下错误.
TypeError:'_ typeype.PyCArrayType'对象不支持项目分配
知道如何解决这个问题吗?我想与之交流
c_function(const char** array_of_string);
Run Code Online (Sandbox Code Playgroud) 我在Android屏幕保护程序上寻找示例代码.我试过谷歌但很难找到任何有用的结果.有没有人对此有任何好的样品?
我看到的是Custom Android Screensaver(或睡眠屏幕)
如果您的意思是创建自己的锁定屏幕,则Android SDK中没有此设置
但我对此并不了解,因为我看到Android Market中存在如此多的屏幕保护应用程序示例.
我可以知道为什么ndarray允许浮点索引访问,这意味着什么?
>>> wk1 = numpy.arange(10)
>>> wk1[1:2.8]
array([1])
>>> wk1 = [1,2,3,4,5,6,7,8,9,10]
>>> wk1[1:2.8]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: slice indices must be integers or None or have an __index__ method
>>>
Run Code Online (Sandbox Code Playgroud) 目前,我正在使用ActionBarSherlock.我要启动SecondActivity从MainActivity.
MainActivity正在使用windowActionBarOverlay打开样式的操作栏.SecondActivity正在使用windowActionBarOverlay关闭了样式的操作栏.因此,这是我的XML的样子.
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:debuggable="false" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/ThemeWithActionBarOverlay"
android:screenOrientation="nosensor" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:theme="@style/ThemeWithoutOverlay">
</activity>
</application>
Run Code Online (Sandbox Code Playgroud)
<resources>
<style name="ThemeWithActionBarOverlay" parent="@style/Theme.Sherlock">
<item name="android:windowActionBarOverlay">true</item>
<item name="abIcon">@drawable/ic_home</item>
<item name="abTitleTextStyle">@style/ActionBarCompatTitle</item>
</style>
<style name="ThemeWithoutOverlay" parent="@style/Theme.Sherlock">
<item name="abIcon">@drawable/ic_home</item>
<item name="abTitleTextStyle">@style/ActionBarCompatTitle</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
但是,通过这样做SecondActivity,我意识到我在动作栏的左上角永远不会有一个向上/向后按钮.虽然有图标显示,但不能按下.只有使用返回相同的主题(ThemeWithActionBarOverlay)MainActivity,才会显示向上/向后按钮.但是,如果我允许SecondActivity使用相同的主题MainActivity,我发现无法关闭windowActionBarOverlay行为.
// SecondActivity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); …Run Code Online (Sandbox Code Playgroud) 我想显示一段长文本如下.这是Flipboard的快照.

为了达到这样的效果,我尝试使用2 TextView秒.
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:text="T" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="76dp"
android:text="op British supermarket Tesco (LSE: TSCO) (NASDAQOTH: TSCDY.US) is due to announce its half year results on" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我得到以下结果.
相当接近.但不是我想要的.这是因为第2行和第3行没有对齐到最左边.第二行和第三行的最左侧空间由TextView大字体占用.

有没有更好的技术我可以使用,比如Flipboard中的那个?
目前,我在我的应用程序中提供了2个主题,基于用户的最后选择 - 黑暗主题和浅色主题.
在主要活动启动期间,我将执行以下操作.
public class MyFragmentActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
// getUserLastThemeChoice will either return R.style.Theme_My_Light or
// R.style.Theme_My_Dark.
this.setTheme(getUserLastThemeChoice());
super.onCreate(savedInstanceState);
Run Code Online (Sandbox Code Playgroud)
在我AndroidManifest.xml,我有以下
<application
...
android:theme="@style/Theme.My.Dark" >
Run Code Online (Sandbox Code Playgroud)
由于硬编码值AndroidManifest.xml,如果用户先前的选择是轻主题,我将观察以下内容.
AndroidManifest.xmlthis.setTheme主要应用程序将更改为白色主题Activity在那里我可以避免这种过渡观察吗?就是这样,根据他们的最后选择直接呈现给用户.
p/s注意,如果从清单中删除主题信息,它将没有多大帮助.由于系统默认使用holo dark.您仍然会观察到过渡,特别是在慢速设备中.
我的传统holo应用程序曾经非常快速地启动.
最近,我花了1年兼职,将holo app移植到材料设计的应用程序.这是我所做的一些重大改变.
ActionBarSherlock到AppCompat工具栏支持库我现在面临的一个问题是我的材料设计应用程序启动速度慢.它比我的全息设计应用程序显着更慢(超过2秒).
注意,在启动应用程序之前,我已经确保我提前终止了进程(通过设置 - >应用程序 - >强制停止).
正如您从视频中看到的那样,一旦我点击图标,ActionBar立即显示全息应用程序.对于材料设计的应用程序,您需要等待大约2至3秒,只有Toolbar将显示.
起初,我想用来TraceView调试和导致缓慢的原因.但是,我意识到TraceView只能在已经启动的应用程序上使用.
我已经证实我没有在我的执行任何耗时的任务Application,Activity和Fragment.由于我的全息应用程序和材料设计的应用程序共享相同的逻辑代码,我无法弄清楚我的材料设计应用程序的速度较慢的原因.
有没有人面临同样的问题?我想知道,有没有什么好方法可以找到根本原因?