所以我用动画制作视图动画:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator" >
<translate
android:duration="1000"
android:fromYDelta="0%"
android:toYDelta="-75%" />
</set>
Run Code Online (Sandbox Code Playgroud)
它在视觉上做我想要的但我也想冻结这个动画的结果.就像我需要以某种方式在动画之后获得结果布局参数(或其他东西?)并将其设置为布局.假设Y-coord的布局从0变为100但我真的不知道什么是起始坐标和什么是产生的坐标.我需要得到结果的coords并将其设置为布局cuz如果不这样做布局返回到动画后的初始位置但我需要让它保持在新位置而不是返回.我还需要2.3.x兼容的解决方案.
更新1
我也试过NineOldAndroids:
ObjectAnimator.ofFloat(rootWrapper, "translationY", -rootWrapper.getHeight()*75/100).start();
Run Code Online (Sandbox Code Playgroud)
这使得视图和视图保持动画位置的动画 - 这正是我想要实现的.
然而,所有控件都是虚拟的.如果我点击那个空屏幕区域然后按钮(那里有b4动画)onClick触发,即使你的布局只有25%的底部可见,75%的休息屏幕看起来是空的.如果设置了xml-animtaions,也会发生同样的情况
animation.setFillAfter(true);
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?所有控件都必须随视图移动.
更新2
代码:
public void showAbout(){
final Animation animShow = AnimationUtils.loadAnimation(this, R.anim.about_in_from_bottom);
animShow.setFillAfter(true);
//ObjectAnimator.ofFloat(rootWrapper, "translationY", -rootWrapper.getHeight()*75/100).start();
animShow.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
LinearLayout.LayoutParams rootlp = (LinearLayout.LayoutParams) rootWrapper.getLayoutParams();
Log.i(this,"rootlp: h: "+rootlp.topMargin+ " / w: "+rootlp.bottomMargin);
rootlp.topMargin = -rootlp.height*75/100;
rootWrapper.setLayoutParams(rootlp);
} …Run Code Online (Sandbox Code Playgroud) 有很多与之相关的问题,但没有一个能帮助我找到解决方案.
我正在尝试将所有联系人从设备同步到远程服务器,并且能够轻松完成,但是当更新/删除/插入(新联系人)等联系人发生更改时无法找到解决方案.
尝试使用ContentObserver但onChange()被多次调用.很难找到联系人更改数据.
public class ContactService extends Service {
private int mContactCount;
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
mContactCount = getContactCount();
Log.d("Contact Service", mContactCount + "");
this.getContentResolver().registerContentObserver(
ContactsContract.Contacts.CONTENT_URI, true, mObserver);
}
private int getContactCount() {
Cursor cursor = null;
try {
cursor = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null, null, null,
null);
if (cursor != null) {
return cursor.getCount();
} else {
return 0;
}
} catch (Exception ignore) { …Run Code Online (Sandbox Code Playgroud) 我发现有几个android wifi应用程序(WiFi管理器,WiFi分析器)显示除了BSSID/SSID等之外的WiFi网络的频道号.但我找不到任何关于他们如何做的信息.我唯一知道的是我可以获得一些wifi频率.也许他们确定了与该频率相对应的频道?有没有办法在android中检测wifi网络的频道?当然这个信息并不是什么大问题,我可以没有它:)但我仍然很好奇......
所以我有android 2.3.5设备,它是NORMAL/HDPI.我的项目中有一个dimens.xml:
...
<dimen name="gameresult_congrats_label_msg_textSize">20sp</dimen>
...
Run Code Online (Sandbox Code Playgroud)
此文件在values-normal/values-hdpi等文件夹中完全相同.在我的第一个活动应用程序中使用以下方
Toast.makeText(this, "textSize is "+getResources().getDimensionPixelSize(R.dimen.gameresult_congrats_label_msg_textSize), Toast.LENGTH_SHORT).show();
Run Code Online (Sandbox Code Playgroud)
它显示了30.我也尝试过:
Toast.makeText(this, "textSize is "+getResources().getDimension(R.dimen.gameresult_congrats_label_msg_textSize), Toast.LENGTH_SHORT).show();
Run Code Online (Sandbox Code Playgroud)
但结果是一样的.但只有当我尝试这个时:
Toast.makeText(this, "textSize is "+getResources().getString(R.dimen.gameresult_congrats_label_msg_textSize), Toast.LENGTH_SHORT).show();
Run Code Online (Sandbox Code Playgroud)
我终于拿到了"20sp"!但那是为什么呢?官方文档称这些方法会返回
资源维度值乘以适当的度量标准.
我通过将我的值改为25来检查这个,我得到38,这意味着aos使用1.5乘数.但为什么?它已经从适当的文件夹中获取价值,这意味着它可以获得准备使用的价值!aos从那里获得1.5倍乘数?我知道这取决于DisplayMetrics.但它如何计算1.5倍?
更新
我理解乘数,但是,你知道,这里真正的问题是双重缩放.这就是为什么我问过这个问题.
所以如果我有一些layout.xml(在res\layout文件夹中),TexView定义如下:
<TextView
android:id="@+id/congratsLabel"
...
android:textSize="@dimen/gameresult_congrats_label_msg_textSize" />
Run Code Online (Sandbox Code Playgroud)
一切都很好看.我的意思是textview就像我期待的那样.
现在让我们在代码中做同样的事情:
TextView congratsLabel = fineViewById(R.id.congratsLabel);
textSize = getResources().getDimension(R.dimen.gameresult_congrats_label_msg_textSize)
congratsLabel.setTextSize(textSize)
Run Code Online (Sandbox Code Playgroud)
这是问题!!! getResources().getDimension()返回一个SCALED值,没关系.但是我的textView的结果大小将比我预期的大1.5,因为setTextSize与SP一起工作,这里是第二个尺度!这就是为什么AOS使得结果文本大小缩放到45(最初定义为20sp).
应用程序抛出异常
android.content.res.Resources $ NotFoundException:字符串资源ID
我的情况并不常见(因为确实存在ID).我问这个问题是自己回答的.
请看下面我的回答为什么会发生这种情况以及它为什么会发生在我身上.
我正在开发手机银行应用程序,显然它管理我们的银行信用卡。所以现在我需要在我的应用程序中实现“将此卡添加到 Google Pay”按钮,但如何为此执行 Google Pay API 请求?我找不到任何相关的文档。在这里所以只有一个问题都有答案,指出我们的银行均应符合PCI DSS和它的路线进行。并且有很多关于如何使用 Google Pay 应用程序手动将任何信用卡添加到 Google Pay 的文档(包括 Google 官方)。但我需要在我的应用程序中自动完成。我意识到我们的银行必须与谷歌和 AFAIK 有一些特殊的协议,我们的银行有它。是否有关于如何实现此类功能的技术文档?
我试图从CONNECTIVITY_ACTION接收BroadcastMessages:
// register BroadcastReceiver on network state changes
final IntentFilter mIFNetwork = new IntentFilter();
mIFNetwork.addAction(android.net.ConnectivityManager.CONNECTIVITY_ACTION); //"android.net.conn.CONNECTIVITY_CHANGE"
registerReceiver(mIRNetwork, mIFNetwork);
Run Code Online (Sandbox Code Playgroud)
和接收者是:
private BroadcastReceiver mIRNetwork = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
android.util.Log.i(TAG,"mIRNetwork: Network State Received: "+intent.getAction());
Bundle extras = intent.getExtras();
if (extras!=null){
android.util.Log.i(TAG,"mIRNetwork: ACTION_BACKGROUND_DATA_SETTING_CHANGED: "+extras.getString(ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED));
android.util.Log.i(TAG,"mIRNetwork: CONNECTIVITY_ACTION: "+extras.getString(ConnectivityManager.CONNECTIVITY_ACTION));
android.util.Log.i(TAG,"mIRNetwork: EXTRA_EXTRA_INFO: "+extras.getString(ConnectivityManager.EXTRA_EXTRA_INFO));
android.util.Log.i(TAG,"mIRNetwork: EXTRA_NO_CONNECTIVITY: "+extras.getString(ConnectivityManager.EXTRA_NO_CONNECTIVITY));
android.util.Log.i(TAG,"mIRNetwork: EXTRA_REASON: "+extras.getString(ConnectivityManager.EXTRA_REASON));
}
}
Run Code Online (Sandbox Code Playgroud)
总之,额外的东西总是空的.我认为,如果我松散WiFi连接,我应该得到EXTRA_NO_CONNECTIVITY(因为它是互联网的唯一途径)或至少从列表中的东西.但没有运气.如果我断开我的WiFi AP接收器得到他的消息,但有额外的空.当我再次打开我的WiFi接收器发射但没有额外的时候......为什么会这样?如何知道该应用程序丢失了任何网络连接?我想是这样的.
networking android connectivity broadcastreceiver android-intent
我要做的事情如下:
private static SharedPreferences sharedPreferencesInstance;
public static SharedPreferences getSharedPreferences(final Context context){
if (context==null)
return sharedPreferencesInstance;
if (sharedPreferencesInstance == null)
sharedPreferencesInstance = context.getApplicationContext().getSharedPreferences("prefs", Context.MODE_PRIVATE);
return sharedPreferencesInstance;
}
private static SharedPreferences.Editor sharedPreferencesEditorInstance;
public static SharedPreferences.Editor getSharedPreferencesEditor(final Context context){
if (context==null)
return sharedPreferencesEditorInstance;
if (sharedPreferencesEditorInstance == null)
sharedPreferencesEditorInstance = context.getApplicationContext().getSharedPreferences("prefs", Context.MODE_PRIVATE).edit();
return sharedPreferencesEditorInstance;
}
Run Code Online (Sandbox Code Playgroud)
但在Context泄漏的意义上它是否安全?
我想获取位于assets目录中的文件的文件大小.我看到很多例子
InputStream myInput = appContext.getAssets().open()
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过简单InputStream的循环读取来确定文件大小,但我正在寻找一种方法来做到这一点File object.
所以我需要一条通往资产的道路,这就是我无法确定的事情......如何获得这条道路?
也试过AssetFileDescriptor通过appContext.getAssets().openFd(),openNonAssetFd()但没有运气 - 得到FileNotFound或可能压缩的例外.
BTW那些openFd方法在developer.android.com上"很好地描述"了.
file = new File(new URI("file:///android_asset/db/call3.db"));
Log.i(APP_TAG, "File name: "+file.getName());
Log.i(APP_TAG, "File path: "+file.getPath());
Log.i(APP_TAG, "File length: "+file.length());
Log.i(APP_TAG, "File isFile: "+file.isFile());
Log.i(APP_TAG, "File exists: "+file.exists());
Run Code Online (Sandbox Code Playgroud)
输出到日志:
04-13 12:10:03.413:INFO(6259):文件名:call3.db
04-13 12:10:03.432:INFO(6259):文件路径:/android_asset/db/call3.db
04-13 12:10:03.444:INFO(6259):文件长度:0
04-13 12:10:03.444:INFO(6259):文件isFile:false
04-13 12:10:03.444:INFO(6259):文件存在:false
当然文件的大小不是0,它是195 584字节.
所以我正在尝试将一个文件从android设备写入windows共享文件夹.我正在使用最新版本的JCIFS和显示可用网络共享的代码正常工作.所以我假设JCIFS和我的局域网,WiFi等一切正常.这是文件上传的代码(实际上我只是想写一个文件Sring to a File):
public boolean save2Samba(String text, String fileName) {
try {
// My Windows shares doesn't require any login/password
// String name="login";//my windows username
// String password="password1";//my windows password
// sSambaFolder contains a path like MYPC/E/SharedFolderName/
String url = "smb://" + sSambaFolder.toLowerCase()+fileName;
SmbFile file = null;
try {
// assume ANONYMOUS is my case but there is no description of this in JCIFS API
NtlmPasswordAuthentication auth = NtlmPasswordAuthentication.ANONYMOUS;
file = new SmbFile(url, auth);
android.util.Log.i("TestApp",url);
// output …Run Code Online (Sandbox Code Playgroud) android ×10
animation ×1
assets ×1
c ×1
connectivity ×1
dimensions ×1
exception ×1
file ×1
google-pay ×1
jcifs ×1
locale ×1
networking ×1
resources ×1
samba ×1
string ×1
sync ×1
textview ×1
wifi ×1