小编use*_*923的帖子

Android中的指南针

我正在尝试使用accelorometer和磁场传感器用Android编程指南针,现在我想知道如何为我的指南针获得正确的角度.

我分别用"加速度"和"磁力"读取加速度计和磁场传感器的值.为了获得角度,我执行以下操作:

float R[] = new float[9];
float I[] = new float[9];
boolean success = SensorManager.getRotationMatrix(R, I, accele, magne);
        if(success) {
            float orientation[] = new float[3];
            SensorManager.getOrientation(R, orientation);
            azimuth = orientation[0]; // contains azimuth, pitch, roll
                            ....
Run Code Online (Sandbox Code Playgroud)

后来,我使用旋转矩阵来放我的针:

rotation.setRotate(azimuth, compass.getWidth() / 2, compass.getHeight() / 2);
canvas.drawBitmap(needle, rotation, null);
Run Code Online (Sandbox Code Playgroud)

现在,getOrientation的文档说,方向[0]应该是围绕z轴的旋转.TYPE_ORIENTATION的文档指出"方位角,磁北方向和y轴之间的角度,围绕z轴(0到359).0 =北,90 =东,180 =南,270 =西".

然而,我的方位角不在0到359之间,而是在-2到2之间.来自getOrientation的方位角到底是什么?如何将其转换为角度?

android android-sensors

14
推荐指数
2
解决办法
1万
查看次数

防止MATLAB打开池

当我parfor在我的代码中安装并使用并行计算工具箱时,MATLAB一旦到达parfor循环就会自动启动它.然而,这有时难以调试,这就是为什么我想阻止MATLAB在某些情况下打开池.那么,我怎么能告诉MATLAB不要打开池?显然我可以通过我的代码并删除所有parfor循环并用普通for循环替换它们,但这很乏味,我可能会忘记撤消我的更改.

编辑:为了指定,我理想地希望parfor循环在设置控件或变量或其他东西时的行为与for完全相同.也就是说,我应该也能够在for循环中放置断点.

parallel-processing matlab parfor

11
推荐指数
2
解决办法
602
查看次数

从ListView隐藏行而不占用空间

我有一个ListView与一个关联的ArrayAdapter,它在几个活动中显示其内容.不幸的是现在有必要,我的ListView在其中一个设置中不会显示其所有元素,而只是"property"未设置为true的那些元素.我想避免使用两个具有不同内容的ArrayAdapter,因为那时我不知何故需要保持它们同步.我这样尝试过(这个方法现在假设在我们想要隐藏某些元素的设置中调用getView):

public View getView(int position, View convertView, Context context) {
....

    if(!arrayitems[position].isProperty()) { //arrayitems is the underlying array
        convertView.setVisibility(View.VISIBLE); 
    } 
    else {
        convertView.setVisibility(View.GONE); 
    }
    return convertView;
}
Run Code Online (Sandbox Code Playgroud)

这有效,但是如果元素的isProperty == true,我会得到一个白色的行.我想在这个意义上让这行不可见,它不再占用任何空间.那可能吗?

用于convertView的xml文件如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:paddingTop="5dp"
    android:paddingBottom="5dp"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/text_item_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="4dp"
            android:maxLines="1"
            android:ellipsize="none"
            android:textSize="12sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/text_item_status"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="12sp"
            android:textStyle="bold" />

    </LinearLayout>

     <TextView android:id="@+id/text_item_text"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:textSize="12sp"
         android:maxLines="3"
         android:ellipsize="none" />

     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="2dp"
         android:orientation="horizontal" >

         <TextView
             android:id="@+id/text_item_rating"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginRight="4dp" …
Run Code Online (Sandbox Code Playgroud)

android android-listview

10
推荐指数
3
解决办法
2万
查看次数

在Objective-C中创建两个线程

我是Xcode和Objective-C的新手,所以我真的不知道我在做什么!;-)
基本上我想拥有一个可以运行两个线程的IPhone应用程序,以后可以UDP Sockets用来与其他应用程序进行通信.

start-Thread/stop-Thread按下UI中的Button 时,我已经放置了函数来响应,现在我想用代码填充它们来实际创建和启动线程.

  • 这里的正确程序是什么?
  • 我需要子类 NSThread吗?
  • 我在哪里实现代码,新线程将执行?

    我看不到运行方法或类似的东西.我想这跟我有什么关系selector,我不明白.

xcode multithreading network-programming objective-c

6
推荐指数
1
解决办法
2万
查看次数

在android中绘制一个箭头

可能重复:
如何绘制箭头(在Android中)?

我想在android中制作一个漂亮的布局布局,为此我想用箭头连接两个视图,看起来非常像这样:

一只忙碌的猫

因此,在箭头的开头,应该是一个视图,并且在箭头的顶端也是如此.

什么是实现这一目标的最佳方式?最简单的只是使用图像?但是后来我无法改变android中箭头的颜色.我可以用形状做某事吗?

谢谢!

android shapes android-layout

0
推荐指数
1
解决办法
4710
查看次数