我有一个图像按钮,我想采取整个设备的宽度.我使用的图像src不像按钮那么长.默认似乎是将它与按钮的cener对齐.相反,我想将它对齐到左边.我尝试过使用布局重力但没有响应.
这是代码..
<LinearLayout
android:id = "@+id/llRoot"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="left" >
<ImageButton
android:id="@+id/ibSend"
android:layout_gravity="left"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/send" >
</ImageButton>
Run Code Online (Sandbox Code Playgroud)
我的Android应用程序有两个位置监听器,一个用于精细监听,一个用于粗略监听.我希望能够检测用户何时关闭和打开其位置服务.
每当我关闭手机GPS或网络位置服务时,就会按预期调用onProviderDisabled方法.当我打开GPS或网络服务时,onProviderEnabled永远不会被调用!
我把下面的一个听众的代码放了....
更新中...
我发现问题与取消注册onPause中的侦听器有关.当我删除代码"locationManager.removeUpdates(myFineLocationListener);" 调用onProviderEnabled()方法.
也许禁用(比如说)GPS的行为会自动取消注册听众?也许我应该在onDestroy而不是onPause()中取消注册监听器?
PS.也许我提到我的活动有一个直接进入设备位置设置页面的按钮是相关的.它充当捷径.我使用此快捷方式禁用/启用位置服务,然后使用"后退"按钮返回到我的应用程序.我将把这个按钮的代码放在这篇文章的最后.
码:
(从onCreate();)调用createLocListeners()方法
void createLocListeners() {
//if null, create a new listener
//myFineLocationListener is a class variable
if (myFineLocationListener == null) {
//Listen for FINE location updates
myFineLocationListener = new LocationListener(){
@Override
public void onLocationChanged(Location location) {
//Do something
}
@Override
public void onProviderDisabled(String provider) {
//This gets called when I change location settings (eg GPS on or off) on the phone }
@Override
public void onProviderEnabled(String provider) {
//This DOES NOT …Run Code Online (Sandbox Code Playgroud) 我正在开发一款Android应用.随着Facebook的offline_access权限即将弃用,我试图使用Graph API来扩展Facebook令牌.
https://graph.facebook.com/oauth/access_token?
client_id=APP_ID&
client_secret=APP_SECRET&
grant_type=fb_exchange_token&
fb_exchange_token=EXISTING_ACCESS_TOKEN
Run Code Online (Sandbox Code Playgroud)
任何人都可以提供详细的代码,演示如何将上述代码实现到Android应用程序并获取刷新的Facebook令牌?
感谢您的时间.
更新二:
进步(我想)!
使用带有facebook请求方法的完整URL会导致基本URL被添加到URL的开头而不是
String refreshUrl = "https://graph.facebook.com/oauth/access_token?client_id=12345678910&client_secret=abcdefghijklmnopqrstuvwxyz&grant_type=fb_exchange_token&fb_exchange_token="+currentAccessToken;
Run Code Online (Sandbox Code Playgroud)
应该用
String refreshUrl = "oauth/access_token?client_id=12345678910&client_secret=abcdefghijklmnopqrstuvwxyz&grant_type=fb_exchange_token&fb_exchange_token="+currentAccessToken;
Run Code Online (Sandbox Code Playgroud)
但是我现在收到响应{"error":{"message":"验证应用程序时出错.应用程序ID无效.","类型":"OAuthException","code":190}}
更新一:
这是我尝试过的.代码完成,即listerner上的OnComplete被调用,但响应不包含新的访问令牌或到期值.
void refreshWithGraph() {
AsyncFacebookRunner extendingAsyncRunner = new AsyncFacebookRunner(facebook);
Bundle parameters = new Bundle();
//the variable currentAccessToken is obtained after authorisation is complete using currentAccessToken = facebook.getAccessToken();
String refreshUrl = "https://graph.facebook.com/oauth/access_token?client_id=12345678910&client_secret=abcdefghijklmnopqrstuvwxyz&grant_type=fb_exchange_token&fb_exchange_token="+currentAccessToken;
extendingAsyncRunner.request(refreshUrl, parameters, new RefreshListener(), null );
}
Run Code Online (Sandbox Code Playgroud)
这是我的RefreshListener版本......
//REFRESH LISTENER
public class RefreshListener extends BaseRequestListener {
public void onComplete(final String response, Object state) {
try { …Run Code Online (Sandbox Code Playgroud) 我想了解numpy的argpartition函数。我已使文档的示例尽可能基本。
import numpy as np
x = np.array([3, 4, 2, 1])
print("x: ", x)
a=np.argpartition(x, 3)
print("a: ", a)
print("x[a]:", x[a])
Run Code Online (Sandbox Code Playgroud)
这是输出...
('x: ', array([3, 4, 2, 1]))
('a: ', array([2, 3, 0, 1]))
('x[a]:', array([2, 1, 3, 4]))
Run Code Online (Sandbox Code Playgroud)
在a = np.argpartition(x,3)行中,第k个元素不是最后一个元素(数字1)吗?如果它是数字1,则x排序时1是否不应该成为第一个元素(元素0)?
在x [a]中,为什么2在1的“前面”是第一个元素?
我缺少什么基本的东西?
我即将完成我的第一个Android应用程序,我正在努力研究如何使用ProGuard保护它.我的应用最低API为7(Android 2.1).我相信如果我将最小API设置为9(Android 2.3),使用Proguard会很容易,但是由于很多设备使用2.1和2.2我不想排除它们.
我所读到的关于在Android上使用Proguard的一切看起来都令人困惑和困难(我对Ant脚本一无所知)有没有人知道使用Proguard for Android与Eclipse的分步指南?
Proguard甚至值得打扰吗?
我想要一个高五行的EditText视图.我想要它只有五行高视觉吸引力(因此它看起来并不局促).下面的代码不起作用,EditText只出现一行高.
我曾试过multilinetext和它的作品在视觉上,但是我想放弃它,因为我想在虚拟键盘说:"下一步"(而不是有自动提供多行文本回车键)
如何让我的EditText框更大?或者,如何在多行文本中使用imeOption"actionNext"?
这段代码不起作用......
<EditText
android:id="@+id/etEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:inputType="text"
android:lines="5" //this has no effect!
android:imeOptions="actionNext"
style="@style/dialogInput" />
Run Code Online (Sandbox Code Playgroud) 我正在用sklearn训练决策树。当我使用时:
dt_clf = tree.DecisionTreeClassifier()
Run Code Online (Sandbox Code Playgroud)
该max_depth参数的缺省值为None。根据文档,如果max_depthis为None,则将节点展开,直到所有叶子都是纯净的,或者直到所有叶子都包含少于min_samples_split样本的叶子为止。
拟合模型后,如何找出max_depth实际值?该get_params()功能无济于事。拟合后,get_params()它仍然说None。
我如何获得实际的电话号码max_depth?
文件:https : //scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html
我下载了 Pycharm 2019.3,并将它与 Python 3 的最新 Anaconda 发行版一起使用。
Jupyter 包已安装 - 我可以在项目解释器的包列表中看到它,我可以从 Windows 命令行运行笔记本。
当我尝试在 Pycharm 中运行一个单元格(或所有单元格)时,弹出错误消息说“未安装 Jupyter 包”。
我的问题与此类似,但我直接在 Windows 上运行。Pycharm jupyter notebook wsl:未安装 Jupyter 包
如何让 Pycharm 识别 Jupyter 包?
在Facebook android教程中,我们被告知使用以下代码来创建密钥哈希:
keytool -exportcert -alias androiddebugkey -keystore~/.android/debug.keystore | openssl sha1 -binary | openssl base64
这是在所有情况下使用的确切代码吗?比如 ~/.android/debug.keystore它应该是什么样的C:/folderone/foldertwo/.android/debug.keystore?
正如您所看到的,我不确定是否需要引号,是否需要完整路径!
有人能够提供一个真实世界的例子吗?
请参阅
https://developers.facebook.com/docs/mobile/android/build/#sso
我想使用AsyncTask来检查InetAddress,例如在下面的代码中.变量tempInet是一个全局变量,用于指示网站是否可联系.
我用代码开始AsyncTask ... new InetAsyncTask().execute("www.facebook.com");
我的问题是我希望AsyncTask在(比方说)10秒后取消.
其他一些问题建议使用get(10,TimeUnit.SECONDS)方法.我想这样做,但不知道在哪里/如何放置get方法.有执行吗?在doInBackground方法中?
此外,get()方法是否阻止主线程?如果有,那有什么意义呢?
任何帮助赞赏.
class InetAsyncTask extends AsyncTask<String, String, Boolean> {
@Override
protected Boolean doInBackground(String... params) {
try {
InetAddress.getByName("www.facebook.com");
return true;
} catch (UnknownHostException e) {
return false;
}
} //end doInBackground function
protected void onPostExecute(Boolean... result) {
tempInet = result[0];
}
} //end class
Run Code Online (Sandbox Code Playgroud)
相关问题
Android开发人员AsyncTask文档
http://developer.android.com/reference/android/os/AsyncTask.html