好的,所以我有一个Android 3.1平板电脑(Acer Iconia Tab,顺便说一句,这很棒)我可以使用Android USB API连接USB大容量存储设备(一个简单的USB记忆棒).
我使用USB主机模式,找到设备,获得连接它的权限(使用BroadcastReceiver).一切都很棒.问题是我不知道该怎么做才能将文件从外部存储目录复制到USB记忆棒.
这是我到目前为止:
final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action)) {
synchronized (this) {
UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
if (device != null) {
// Got to a point where I should set up connection
// I'm setting up a very simple connection, just want some file transfer
UsbInterface intf = device.getInterface(0);
UsbEndpoint endpoint = intf.getEndpoint(0);
UsbDeviceConnection connection …Run Code Online (Sandbox Code Playgroud) 我正在使用Android拖放API,并尝试将拖动阴影的锚点设置为触摸所在的点View.dafault行为是将锚点放在中间位置View.
我做了一些研究,似乎可以通过覆盖类中的onProvideShadowMetrics (Point shadowSize, Point shadowTouchPoint)方法来完成DragShadowBuilder.根据我的理解,如果我改变它的x,y坐标shadowTouchPoint应该修改拖动锚的坐标.
我做的是DragShadowBuilder像这样扩展类:
class EventDragShadowBuilder extends DragShadowBuilder {
int touchPointXCoord, touchPointYCoord;
public EventDragShadowBuilder() {
super();
}
public EventDragShadowBuilder(View view, int touchPointXCoord,
int touchPointYCoord) {
super(view);
this.touchPointXCoord = touchPointXCoord;
this.touchPointYCoord = touchPointYCoord;
}
@Override
public void onProvideShadowMetrics(Point shadowSize,
Point shadowTouchPoint) {
shadowTouchPoint.set(touchPointXCoord, touchPointYCoord);
super.onProvideShadowMetrics(shadowSize, shadowTouchPoint);
}
}
Run Code Online (Sandbox Code Playgroud)
在Fragment我使用拖放的地方,我创建了两个侦听器来启动一个拖动事件View:
mEventLongClickListener = new OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
EventDragShadowBuilder shadowBuilder …Run Code Online (Sandbox Code Playgroud) 我有一个我正在膨胀的布局,以便动态地将TableRows添加到TableLayout中.我使用layout_weight将列拉伸到所需的宽度.
该表放在ScrollView中,因此我可以在生成的行之间滚动.我还有一个表头,我把它放在一个LinearLayout上面.我这样做是因为我不想滚动标题.这也是我不使用layout_span而不是layout_weight的原因.
问题是TableRow中的一个视图是一个CheckBox,我希望它居中,但由于layout_width属性为'0',我不能使用layout_gravity ="center"来居中它.
这是xml文件:
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/order_form_line_TableRow"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/order_table_row_product_description_TextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.22"
android:maxLines="2"
android:textSize="18sp" />
<CheckBox
android:id="@+id/order_table_row_present_CheckBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.08" />
<EditText
android:id="@+id/order_table_row_facings_EditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.10"
android:inputType="number" />
<EditText
android:id="@+id/order_table_row_free_cu_given_EditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.10"
android:inputType="number" />
<EditText
android:id="@+id/order_table_row_order_quantity_EditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.10"
android:inputType="number" />
<EditText
android:id="@+id/order_table_row_free_order_EditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.10"
android:inputType="number" />
<Spinner
android:id="@+id/order_table_row_wholesaler_Spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.15" />
<EditText
android:id="@+id/order_table_row_delivery_date_EditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.15" …Run Code Online (Sandbox Code Playgroud) 我创建的应用程序遵循教程http://www.techotopia.com/index.php/Using_Fragments_in_Android_-_A_Worked_Example 但我有一个错误.
logcat的:
05-02 08:16:22.044: D/dalvikvm(1846): Late-enabling CheckJNI
05-02 08:16:22.080: D/AndroidRuntime(1846): Shutting down VM
05-02 08:16:22.080: W/dalvikvm(1846): threadid=1: thread exiting with uncaught exception (group=0xa4d81b20)
05-02 08:16:22.096: E/AndroidRuntime(1846): FATAL EXCEPTION: main
05-02 08:16:22.096: E/AndroidRuntime(1846): Process: com.example.myfragmentexample, PID: 1846
05-02 08:16:22.096: E/AndroidRuntime(1846): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfragmentexample/com.example.myfragmentexample.MainActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-02 08:16:22.096: E/AndroidRuntime(1846): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-02 08:16:22.096: E/AndroidRuntime(1846): …Run Code Online (Sandbox Code Playgroud) 想象一下,我在屏幕上绘制了一个中心坐标为(cx,cy)的圆,并且在该圆上选择了一个随机点(A)。
通过获得点A的坐标,我需要找到(a)的角度。
更新:
我尝试使用以下公式:
Math.toDegrees(Math.asin(((x - cx) / radius).toDouble()))
Run Code Online (Sandbox Code Playgroud)
实际上是相反的(圆是通过向该圆角进给而创建的):
x = radius * Math.sin(Math.toRadians(angle.toDouble())) + cx
y = radius * Math.cos(Math.toRadians(angle.toDouble())) + cy
Run Code Online (Sandbox Code Playgroud)
但由于公式中不存在y坐标,因此答案可能是错误的。
我把这段代码作为我学校的练习:
#include <stdio.h>
main()
{
int unknown(int a, int b)
{
if (b == 1)
return a;
else
return a + unknown(a, b - 1);
}
printf("Value = %i", unknown(3, 4));
}
Run Code Online (Sandbox Code Playgroud)
结果是"价值= 12".我似乎无法理解为什么.AFAIK它应该是a = 3,b = 4然后是3 + 4,对吧?