我的应用程序中有一个ImageView,它可以位于屏幕上的任何位置
在触摸时我想将此视图移动到屏幕的中心.我使用Translate Animation及其RELATIVE_TO_PARENT功能尝试了此功能,如下所示
TranslateAnimation translateAnimation1 = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_PARENT,0.0f,
TranslateAnimation.RELATIVE_TO_PARENT,0.5f,
TranslateAnimation.RELATIVE_TO_PARENT,0.0f,
TranslateAnimation.RELATIVE_TO_PARENT,0.5f);
Run Code Online (Sandbox Code Playgroud)
但ImageView从当前位置向下移动50%(屏幕).
有没有办法将此视图移动到屏幕中心,无论其当前位置如何?
我有一个在前台模式下运行的服务,我想检测运行Android 4.2或更高版本的平板电脑上的用户会话之间的切换.
我可以注册任何广播接收器以获得通知吗?
我注意到,只要在锁定屏幕上选择了另一个用户会话,Google音乐就会停止音乐播放.它如何检测开关?
答案解释
感谢@CommonsWare的正确答案.我将解释一下如何检测用户开关.
首先要知道文档明确说明接收者必须通过注册Context.registerReceiver.因此,做一些事情:
UserSwitchReceiver receiver = new UserSwitchReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction( Intent.ACTION_USER_BACKGROUND );
filter.addAction( Intent.ACTION_USER_FOREGROUND );
registerReceiver( receiver, filter );
Run Code Online (Sandbox Code Playgroud)
然后在接收器中,您还可以检索用户ID.这是一个小片段:
public class UserSwitchReceiver extends BroadcastReceiver {
private static final String TAG = "UserSwitchReceiver";
@Override
public void onReceive(Context context, Intent intent)
{
boolean userSentBackground = intent.getAction().equals( Intent.ACTION_USER_BACKGROUND );
boolean userSentForeground = intent.getAction().equals( Intent.ACTION_USER_FOREGROUND );
Log.d( TAG, "Switch received. User sent background = " + userSentBackground + "; User sent foreground = …Run Code Online (Sandbox Code Playgroud) 我希望有一个活动(2),半透明的方面超过另一个活动(1),在屏幕的顶部对齐(4).

我尝试将这些主题分配给活动编号2:
<style name="Theme.CustomDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/black</item>
</style>
<style name="CustomTheme">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但结果总是3.
如果我<item name="android:windowIsFloating">false</item>在CustomTheme结果中设置为2.
谁能告诉我怎样才能得到4?谢谢!
更新:这是我的活动2布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:background="#0000">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="#FFFFFF">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu" android:layout_centerHorizontal="true"/>
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的XCTestCase实现,测试按下按钮并期望显示警报控制器.问题是该tap()方法不起作用.在相关按钮的IBAction中放置一个断点我意识到逻辑甚至没有被调用.
class uitestsampleUITests: XCTestCase {
var app: XCUIApplication!
override func setUp() {
super.setUp()
continueAfterFailure = false
app = XCUIApplication()
app.launch()
}
func testButton() {
let button = app.buttons["Button"]
button.tap()
expectationForPredicate(NSPredicate(format: "exists == 1"), evaluatedWithObject: button, handler: nil)
waitForExpectationsWithTimeout(5.0, handler: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
此外,复制button.tap()指令使测试通过,如下所示:
func testButton() {
let button = app.buttons["Button"]
button.tap()
button.tap()
expectationForPredicate(NSPredicate(format: "exists == 1"), evaluatedWithObject: button, handler: nil)
waitForExpectationsWithTimeout(5.0, handler: nil)
}
Run Code Online (Sandbox Code Playgroud)
我在Xcode 7.3.1中遇到这个问题我错过了什么吗?这是一个错误吗?
我正在开发一个 Swift 框架 (MyFramework),它依赖于用 Objc ( NewRelic )编写的第三方静态库
我正在使用 CocoaPods 1.4.0,并且我已经像这样声明了我的 podspec:
...
s.source_files = 'MyFrame/Classes/**/*'
s.static_framework = true
s.dependency 'NewRelicAgent', '6.1.1' # Obj-c
s.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(PODS_ROOT)/NewRelicAgent/NewRelicAgent/NewRelicAgent.framework/Headers', 'SWIFT_INCLUDE_PATHS' => '$(PODS_TARGET_SRCROOT)/MyFrameFramework' }
s.preserve_paths = 'MyFrameFramework/MyFrame.modulemap'
Run Code Online (Sandbox Code Playgroud)
从我在不同帖子中读到的,我认为我在这里做的是:
static_framework能够使用静态库NewRelic。这是我的MyFrame.modulemap:
framework module LGResources {
umbrella header "MyFrameFramework.h"
export *
module * { export * }
}
Run Code Online (Sandbox Code Playgroud)
而这个MyFrameFramework.h:
//! Project version number for LGResources.
FOUNDATION_EXPORT double MyFrameVersionNumber; …Run Code Online (Sandbox Code Playgroud) 我正在使用自动续订订阅.当应用程序成功完成交易后,它会将收据发送到我们的服务器以验证它,并检查收据中是否存在最后一个交易标识符.
有时,我们的服务器会返回一个错误,指出在收据中找不到交易标识符.我在应用程序中已在本地确认.即使刷新收据后,有时也找不到交易标识符.
此外,购买成功,因为尝试再次购买相同的订阅提示iOS弹出说明订阅当前是活动的.
显然,这种奇怪的行为发生在沙盒环境中.另请注意,我最多使用3个测试用户在它们之间来回切换.
有没有人遇到过类似的问题?
关于发生了什么的任何想法?
处理通用链接时,如何排除特定的子域?如果要排除help.example.com在URL 文件中,以便在浏览器中打开该URL ,我应该在授权文件中添加些什么?
我的权利文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:www.example.com</string>
<string>applinks:*.example.com</string>
</array>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud) 我正在努力了解Android(Java)中字符串和内存管理的情况.
为简化起见,请看一下这段简单的代码:
public void createArray(){
String s = "";
String foo = "foo";
String lorem = "Lorem ipsum ad his scripta blandit partiendo, eum
fastidii accumsan euripidis in, eum liber hendrerit an.";
ArrayList<Item> array = new ArrayList<Item>();
for( int i=0; i<20000; i++ ){
s = foo.replace("foo", lorem);
array.add( new Item(s) );
}
System.gc();
}
private class Item{
String name;
public Item(String name){
this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
如果执行,createArray将在内存中分配超过5Mb.即使使用该System.gc()指令,循环后也不会释放内存.
现在,如果我们更换s = foo.replace("foo", lorem);用s = …
Android默认浏览器允许匿名浏览.是否可以检测用户何时在默认Android浏览器应用程序的隐身标签中浏览?(我对用户访问的网址没兴趣)
我正在使用Content Observer对象来接收有关用户浏览历史记录的更新.当用户打开隐身标签时,我没有收到任何人所期望的任何更新.我想知道的是我怎么知道用户正在匿名浏览.
我可以知道浏览器应用程序位于前台,我知道没有注册历史记录网址,但我可以检索哪些其他信息以确保用户在隐身标签中进行浏览?
更新:
伙计们,谢谢你的评论.我确切地知道我在问什么.我知道隐身模式的重点,只有默认浏览器使用ContentProvider记录浏览历史记录.
我正在写一个家长控制应用程序,所以如果有人能回答这个问题我会非常感激.
我有一个已发布的应用程序报告java.lang.UnsatisfiedLinkError某些设备崩溃.更准确地说,应用程序在启动时崩溃并显示以下日志消息:
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load qcc: findLibrary returned null
实际崩溃在System.loadLibrary("qcc");指令中,因此应用程序无法确定找到库.
问题是我自己无法重现这个问题.实际上相同的apk在许多不同的设备和版本上完美地工作.
该应用程序使用由第三人编写和编译的两个C库.它们是使用arm-linux-androideabi-4.6工具链编译的,我将它们集成到我nkd-build使用以下Android.mk文件运行的项目中:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libqcc
LOCAL_SRC_FILES := qcc/libqcc.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libqpe
LOCAL_SRC_FILES := qpe/libqpe.so
include $(PREBUILT_SHARED_LIBRARY)
Run Code Online (Sandbox Code Playgroud)
该错误正在不同的设备上报告,但目前所有这些都是以下Android版本之一:2.2,2.2.1或2.2.2.
我认为这可能是架构问题或安装过程中的奇怪问题.
有谁知道是什么问题?
更新:
我意识到我可以在Android 2.2模拟器中重现这个问题.这是我可以从logcat收集的额外信息.
11:14:59.962 I/dalvikvm( 287): Unable to dlopen(/data/data/.../lib/libqcc.so): Cannot load library: link_image[1995]: failed to link libqcc.so
11:14:59.962 W/dalvikvm( 287): Exception Ljava/lang/UnsatisfiedLinkError;
Run Code Online (Sandbox Code Playgroud) android ×6
ios ×4
android-ndk ×1
browser ×1
cocoapods ×1
frameworks ×1
ios7 ×1
iphone ×1
java ×1
memory-leaks ×1
objective-c ×1
string ×1
swift ×1
transparency ×1
xcode ×1