我成功检测到手机绕轴的 0-360 度旋转(滚动),但现在我很难设计一种有效的算法来检测一整圈。我的工作但我认为不像我想要的那样优雅和有效的算法是:
private boolean detectRoll;
private boolean[] checkpointsR = new boolean[4];
private boolean fullRollTurn;
public void detectingRoll() {
setDetectRoll(true);
checkpointsR[0] = true;
for (int i = 1; i < 4; i++) {
if (roll > 90 * i && roll < 90 * (i + 1)
&& checkpointsR[i - 1] == true) {
checkpointsR[i] = true;
}
}
if (areAllTrue(checkpointsR) && roll > 0 && roll < 45) {
fullRollTurn = true;
// reset rollCheckpoints
for (int i = …Run Code Online (Sandbox Code Playgroud) 我想在Javascript中创建一个类.这堂课应该有
怎么做到这一点?
我添加了一个drawable到我的应用程序,我可以触摸移动,并根据手指移动速度,我想做不同的动作.
我检查了事件,我只能使用MotionEvent.ACTION_MOVE来检测是否有运动.所以我保存了最后一个动作的时间戳并获得了实际值,我计算了动作的增量距离,并使用了公式
速度=距离/时间
但是,速度值显示各种数字,从0到aprox.6但是如果我慢慢地或快速地使用我的手指并不重要.我应该修改什么才能获得触摸移动的速度?
我使用以下代码:
@Override
public boolean onTouch(View view, MotionEvent motionEvent)
{
final int X = (int) motionEvent.getRawX();
final int Y = (int) motionEvent.getRawY();
switch (motionEvent.getAction() & MotionEvent.ACTION_MASK)
{
case MotionEvent.ACTION_DOWN:
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
_xDelta = X - lParams.leftMargin;
_yDelta = Y - lParams.topMargin;
oldTimeStamp=System.currentTimeMillis();
break;
case MotionEvent.ACTION_UP:
speed=0;
textView.setText("speed: " + speed);
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_MOVE:
timeStamp= System.currentTimeMillis();
long diff=timeStamp-oldTimeStamp;
double dist=Math.sqrt(Math.pow(_xDelta,2)+Math.pow(_yDelta,2));
double speed=dist/diff;
textView.setText("speed: " + speed);
oldTimeStamp=timeStamp;
RelativeLayout.LayoutParams layoutParams …Run Code Online (Sandbox Code Playgroud) 我有tabbar5个标签,我在第4个标签上添加了徽章.我想在服务器执行某些操作后更新我的徽章值.但不知道怎么能这样做.此外,我想从不同的更新徽章价值activities.添加徽章的代码片段Tabbar
TabWidget tabs = (TabWidget) findViewById(android.R.id.tabs);
badge = new BadgeView(context, tabs, 3);
badge.setTextSize(12);
badge.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
badge.setText(pref.getString("balance", "0"));
badge.toggle();
Run Code Online (Sandbox Code Playgroud)
先感谢您
在Google Developer的API中有一个trimToSize()方法,我无法找到/使用它.如何清除或缩小LRU Cache的大小?
我使用以下类(android中的简单2D图形)在视图上创建了两个位图,并徘徊以实现该位图可以独立移动。我正在为此调用motionevent方法。
当前问题,我不明白为什么下面的代码中只有一个对象向右移动。例如,使用此代码,仅“非”位图被移动,我希望两个位图彼此独立地移动。
scenrio:我可以用我的两个手指,每个对象一个,独立移动位图。但我不知道如何实现这一目标。
public class TouchView extends View {
private Drawable cross;
private Rect crossBounds = null;
private Drawable not;
private Rect notBounds = null;
private int x1, y1, x2, y2 ;
boolean flag = true;
private void intialize ()
{
int w1 = cross.getIntrinsicWidth();
int h1 = cross.getIntrinsicHeight();
x1 = 100;
y1 = 100;
crossBounds = new Rect(x1-w1/2, y1-w1/2, x1+w1/2, y1+h1/2);
int w = not.getIntrinsicWidth();
int h = not.getIntrinsicHeight();
x2 = 300;
y2 = 300;
notBounds = new Rect(x2-w/2, …Run Code Online (Sandbox Code Playgroud) 我想在用户点击按钮时将我的应用程序中的屏幕布局更改为全屏但是它不起作用,我的代码是:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnFullScreen = (Button) findViewById(R.id.btnFullScreen);
btnNormalScreen = (Button) findViewById(R.id.btnNormalScreen);
btnFullScreen.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
setTheme(R.style.AppBaseThemeFullScreen);
}
});
btnNormalScreen.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
setTheme(R.style.AppBaseTheme);
}
});
}
Run Code Online (Sandbox Code Playgroud)
我的全屏主题是:
<style name="AppBaseThemeFullScreen" parent="android:Theme.Light">
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我的师范主题是
<style name="AppBaseTheme" parent="android:Theme.Light">
<item name="android:windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
所以,如果有任何方法可以帮助我.
在我的Android应用程序中,我必须在按钮单击事件上弹出一个对话框.但是,当我点击按钮时,应用程序停止工作.我将预先设计的布局加载到对话框中.我将发布一个代码段.
Button login = (Button) findViewById(R.id.btn_login);
login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Dialog dialog = new Dialog(getApplication());
dialog.setContentView(R.layout.journey_details);
dialog.setTitle("Android Custom Dialog Box");
Button dialogButton = (Button) dialog.findViewById(R.id.btn_start_jrny);
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
Run Code Online (Sandbox Code Playgroud)
它在Log cat中显示以下错误.
E/AndroidRuntime(1412): FATAL EXCEPTION: main
E/AndroidRuntime(1412): Process: com.xont.geotracker, PID: 1412
E/AndroidRuntime(1412): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not …Run Code Online (Sandbox Code Playgroud)