这个问题已经在这里提出但是没有好的答案.
所以基本上我有一个在后台运行的intent服务来做一些事情,一旦完成,我使用resultreceiver将结果发送回活动,所以我需要知道的是:
我想要做的是,我想开始缩放画布中的特定点,缩放工作正常但我的问题是我不知道如何计算在缩放时移动画布多少,请注意我我没有使用canvas.scale.
我只是在缩放时增加系统中每2个单元之间的距离,它的工作正常.
那么是否有任何方程可以帮助我找出在特定点缩放时偏移画布的数量?
假设我想缩放点(0,4)如何知道在缩放时移动画布有多少?
我使用executorService使用此代码一次只执行一个任务
executorService=Executors.newSingleThreadExecutor();
Run Code Online (Sandbox Code Playgroud)
我Thread.activeCount()用来获取活动线程的数量,但每当我向executorService提交一个可运行的任务时,活动线程的数量会增加1.怎么可能?
我想newSingleThreadExecutor()只允许一次只执行一个任务.为什么线程数量不断增加?不应该线程数只增加一个而不是更多?
请注意,我future甚至在提交新任务之前也使用取消所有runnable的执行,并且它工作正常; 所有runnable都被打断了.但是,活动线程的数量不断增加.
编辑:这是每当我按下按钮时调用的代码(Worker只是一个实现runnable的类):
private void handle() {
executorService=Executors.newSingleThreadExecutor();
Worker worker=new Worker();
future=executorService.submit(new Worker());
}
Run Code Online (Sandbox Code Playgroud) 我需要相对于画布获得触摸x和y,以便在我移动并缩放画布后检查碰撞和类似的事情.
每当我翻译画布时,我已经设法获得了触摸坐标,或者使用以下代码在原点(0,0)周围缩放它:
private float convertToCanvasCoordinate(float touchx, float touchy) {
float newX=touchx/scale-translatex;
float newY=touchy/scale-translatey
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我将画布围绕另一个点进行缩放,例如canvas.scale(scale,scale,50,50),它就不起作用了.
我知道它应该不起作用,但我无法弄清楚如何解决它.我已经查看了其他问题,但如果按照特定点进行缩放,没有一个答案谈到如何获得坐标.
我正在尝试创建类似于Youtube应用的视图,如下所示:
点击后,我将打开一个对话框,如下所示:
是否有任何已经由android构建的视图或库可以帮助我创建它或者我是否需要自己创建它?
我试着搜索但找不到任何东西.
这是我的firebase的屏幕截图:
我试图在firebase数据库中检索最高的100分我使用此代码将新节点添加到firebase:
Map<String, String> post1 = new HashMap<String, String>();
post1.put("name",name);
post1.put("score",score);
myRef.push().setValue(post1);
Run Code Online (Sandbox Code Playgroud)
这是我用来检索最高100分不起作用的代码(代码有效,但它没有检索到最高的100分)
Query queryRef = myRef.orderByChild("score").limitToFirst(100);
queryRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) {
Score score=postSnapshot.getValue(Score.class);
Log.d("test"," values is " + score.getName() + " " + score.getScore());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用lifeCycleOwner和lifecycleObserve。当我调用lifecycleOwner.getLifecycle()。addObserver(this)时,出现以下异常 。
invalid parameter type. Must be one and instanceof LifecycleOwner
Run Code Online (Sandbox Code Playgroud)
代码如下所示
public class TestActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_activity);
new TestObserver(this,this);
}
}
public class TestObserver implements LifecycleObserver{
public TestObserver(LifecycleOwner lifecycleOwner, Context context){
lifecycleOwner.getLifecycle().addObserver(this);
}
}
Run Code Online (Sandbox Code Playgroud)
编辑: 根据要求Build.gradle文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.test"
minSdkVersion 14
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies …Run Code Online (Sandbox Code Playgroud) android ×8
canvas ×2
android-architecture-components ×1
coordinates ×1
dialog ×1
firebase ×1
math ×1
onclick ×1
textview ×1