所以,我希望在我的布局上有一个滚动视图.我这样做了,得到了a scroll view can only have one child:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="95dip"
android:layout_marginRight="5dip"
android:layout_marginTop="10dip"
android:text="Latitude: "
android:textSize="15dip" >
</TextView>
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="unknown"
android:textSize="15dip" >
</TextView>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="90dip"
android:layout_marginRight="5dip"
android:text="Longitute: "
android:textSize="15dip" >
</TextView>
<TextView
android:id="@+id/TextView04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="unknown"
android:textSize="15dip" >
</TextView>
</LinearLayout>
<Button
android:id="@+id/button1"
android:layout_width="130dip"
android:layout_height="30dip"
android:layout_marginLeft="95dip"
android:layout_marginTop="10dip"
android:text="Find Coordinates" …Run Code Online (Sandbox Code Playgroud) 我需要 Android 设备上图像的 File 对象。
我正在使用一个函数来获取给定 URI 的 FileInputStream。
FileInputStream getSourceStream(Uri u) throws FileNotFoundException {
FileInputStream out = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
ParcelFileDescriptor parcelFileDescriptor =
getContentResolver().openFileDescriptor(u, "r");
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
out = new FileInputStream(fileDescriptor);
} else {
out = (FileInputStream) getContentResolver().openInputStream(u);
}
return out;
}
Run Code Online (Sandbox Code Playgroud)
这将返回一个 FileInputStream。我需要的是图像的 File 对象。如何从 FileInputStream 获取文件?
更新
这就是我获取 URI 的方式:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, ""), PICK_IMAGE);
Run Code Online (Sandbox Code Playgroud)
然后onActivityResult我得到图像的 URI。
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent …Run Code Online (Sandbox Code Playgroud)