我是Android的新程序员,所以请原谅我的知识和英语,因为它不是我的第一语言.所以我有一个带有标签的日志:"szipinf"和文字:"初始化膨胀状态",我不知道它意味着什么......我也看到只有当我在手机上测试游戏时,在模拟器上它没有出现.如果有人能告诉我这是什么意思,我真的很感激.
在PHP中进行gzip deflate请求后,我收到了偏移块中的缩减字符串,如下所示
示例缩短为显示格式:
00001B4E
¾”kŒj…Øæ’ìÑ«F1ìÊ`+ƒQì¹UÜjùJƒZ\µy¡ÓUžGr‡J&=KLËÙÍ~=ÍkR
0000102F
ñÞœÞôΑüo[¾”+’Ñ8#à»0±R-4VÕ’n›êˆÍ.MCŽ…ÏÖr¿3M—èßñ°r¡\+
00000000
Run Code Online (Sandbox Code Playgroud)
因为分块格式,我无法膨胀.用Hex编辑器手动删除偏移并读取gzip存档后,我可以确认数据没有损坏.我想知道是否有一个正确的方法来解析这个分块的gzip缩减响应到一个可读的字符串?
我可能能够将这些偏移分开并将数据连接在一起以调用gzinflate,但似乎必须有一种更简单的方法.
在我的应用程序中,我有一个微调器和一个ViewStub,取决于微调器中的用户项目选择,我必须膨胀不同的布局并在微调器下方显示膨胀的布局.当我的应用程序启动时,ViewStub会在第一次从微调器中选择任何项目时成功膨胀布局.当我尝试从微调器中选择一个新项时,它会在下面引发异常
java.lang.IllegalStateException: ViewStub must have a non-null ViewGroup viewParent
Run Code Online (Sandbox Code Playgroud)
到目前为止我的代码是
@Override
public void onItemSelected(AdapterView<?> pParent, View pView, int pPosition, long pId) {
if(pPosition == 1){
m_cStub.setLayoutResource(R.layout.text_form);
}else if(pPosition == 2){
m_cStub.setLayoutResource(R.layout.integer_form);
}
View inflated = m_cStub.inflate();
}
Run Code Online (Sandbox Code Playgroud)
m_cStub是在Activity的onCreate()内创建的ViewStub对象.
这是我的主要布局xml代码
<RelativeLayout..................>
<spinner......................./>
<ViewStub android:id="@+id/dynamic_form_layout"
android:inflatedId="@+id/dynamic_form_inflated_id"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
谁能告诉我哪里出错了.如果您有任何其他解决方案可以解决此问题,请分享.
谢谢.
我正在视图持有者/适配器模式之后创建"文档"的网格视图.在活动中,我从网络类中获得回调,因此我需要能够在不同的时间更新每个网格单元.
我这样做的方法是通过从对象元素(文档)到相应的视图持有者的映射映射.我需要这样做,因为适配器正在循环使用单元格,所以有时我可以收到一个回调来更新一个不可见的单元格,在这种情况下,回调信息将被忽略.
我可以看到getView适配器的方法被多次调用为位置0.我一直在读这是正常的.
inflating position 0 *** progressBar 1
recycling position 0
recycling position 0
inflating position 0 *** progressBar 2
recycling position 0
recycling position 0
recycling position 0
recycling position 0
recycling position 0
recycling position 0
Run Code Online (Sandbox Code Playgroud)
UI我需要从回调中更新的一个元素是一个进度条,我通过添加viewHolder到与文档关联的Map来跟踪.
除了第一个方法之外,这整个方法适用于所有位置.我可以识别的唯一区别是这些多次调用,getView所以我从那里开始调试.在progressBar我更新为" progressBar2",这是最新的geView夸大,但实际上它并没有给回应setVisible(View.VISIBLE).然后我对代码进行了一些更改以更新" progressBar1"并且它可以工作.
这意味着getView相同位置膨胀两次,但第二次没有被使用或显示.
我能做错什么?为什么progressbar1工作而progressbar2没有?我希望这getView会给我一个与职位相对应的最新观点.
谢谢.
适配器:
public class DocumentPickerGridViewAdapter extends ArrayAdapter<Document> implements Filterable {
private final DocumentPickerGridViewController picker;
private ArrayList …Run Code Online (Sandbox Code Playgroud) 我正在通过nodejs将java应用程序中的压缩数据发送到网页.使用java deflater和base64编码压缩数据.在网页上我试图用https://github.com/dankogai/js-deflate来扩充数据,但它不起作用(空结果).我错过了什么吗?
Java方面:
private String compress(String s) {
DeflaterOutputStream def = null;
String compressed = null;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
// create deflater without header
def = new DeflaterOutputStream(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true));
def.write(s.getBytes());
def.close();
compressed = Base64.encodeBase64String(out.toByteArray());
System.out.println(compressed);
} catch(Exception e) {
Log.c(TAG, "could not compress data: " + e);
}
return compressed;
}
Run Code Online (Sandbox Code Playgroud)
Javascript方面:
var data = RawDeflate.inflate(Base64.fromBase64(compressed));
Run Code Online (Sandbox Code Playgroud) 所以,我试图用Java对zip文件进行只读访问,以多线程方式解压缩,因为我使用枚举和输入流的ZipFile/ZipEntry的标准简单单线程解决方案和什么不导致它采取大约五个完整的秒钟,只需要将一个50兆的zipfile解压缩到内存中,这需要一秒钟的AT MOST让我的磁盘无需解压缩即可读取.
然而,整个Java zip库被同步到令人难以置信的令人讨厌的程度,毫无疑问,因为它完全被抽象用于读/写等.在相同的代码中,而不是具有良好的有效非同步只读代码.
我看过第三方Java库,它们都是大型的VFS库,比使用大象枪射击苍蝇更糟糕,或者它们具有性能优势的唯一原因是它们多线程到达无论如何,大多数线程都在磁盘IO上阻塞.
我想要做的就是将zipfile拉入byte [],分叉一些线程,然后处理它.没有理由以任何方式对任何事情进行任何同步,因为我在内存中单独使用的每个解压缩文件没有交互.
为什么一定要这么难?
我有一个带有"添加"和"删除"按钮的活动.
"添加按钮"会使视图膨胀,"删除按钮"会删除选定的视图.
当我使用"添加按钮"给视图充气时,它会自动绘制在任何先前的隐藏视图下方.
我想让用户有可能上下移动每个充气的视图,这样他就可以改变它们在屏幕上显示的顺序(在一种拖拽效果中)
+---------------------+ +---------------------+
| +-----------------+ | | +-----------------+ |
| | View 1 | | | | View 2 | |
| +-----------------+ | | +-----------------+ |
| | --> | |
| +-----------------+ | | +-----------------+ |
| | View 2 | | | | View 1 | |
| +-----------------+ | | +-----------------+ |
+---------------------+ +---------------------+
Run Code Online (Sandbox Code Playgroud)
是否可以指定每个视图膨胀的"位置"?(例如,低于或高于当前选定的视图?)
如果没有,达到预期效果的最佳方法是什么?
(如果您认为可能有帮助,请随时询问任何代码段)
我有一个数据样本:
byte[] b = new byte[]{120, 1, -67, -107, -51, 106, 20, 81, 16, -123, 107, 18, -51, -60, 31, -30, 117, -4, -53, -60, -123, 25, 70, 71, 23, -111, 89, 12, 8, -83, 49, 4, -14, -93, -63, 73, 32, 89, -55, -112, -123, 10, -30, 66, 69, -110, 69, -64, -107, -77, 8, -72, 21, 23, -82, 5, -97, -64, 55, -48, -73, -16, 97, 4, -3, 14, -23, -110, 75, 59, 125, 39, 8, -10, -123, …Run Code Online (Sandbox Code Playgroud) 我正在尝试直接从php://input流中解压缩 zip 文件。我正在运行 Laravel Homestead, PHP 7.1.3-3+deb.sury.org~xenial+1,端点为myproject.app/upload,这是curl命令:
curl --request POST \
--url 'http://myproject.app/upload' \
--data-binary "@myfile.zip" \
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的所有方法的列表,但都失败了:
dd(file_get_contents('compress.zlib://php://input'));
Run Code Online (Sandbox Code Playgroud)
file_get_contents():不能将输入类型的流表示为文件描述符
$fh = fopen('php://input', 'rb');
stream_filter_append($fh, 'zlib.inflate', STREAM_FILTER_READ, array('window'=>15));
$data = '';
while (!feof($fh)) {
$data .= fread($fh, 8192);
}
dd($data);
Run Code Online (Sandbox Code Playgroud)
“”
$zip = new ZipArchive;
$zip->open('php://input');
$zip->extractTo(storage_path() . '/' . 'myfile');
$zip->close();
Run Code Online (Sandbox Code Playgroud)
ZipArchive::extractTo(): 无效或未初始化的 Zip 对象
以下是我在该主题上找到的所有链接:
http://php.net/manual/en/wrappers.php#83220
http://php.net/manual/en/wrappers.php#109657
http://php.net/manual/en/wrappers.compression.php#118461
https://secure.phabricator.com/rP42566379dc3c4fd01a73067215da4a7ca18f9c17
https://arjunphp.com/how-to-unpack-a-zip-file-using-php/
我开始认为不可能使用 PHP 的内置 zip 功能对流进行操作。编写临时文件的开销和复杂性将非常令人失望。有谁知道如何做到这一点,或者这是一个错误?
我认为标题涵盖了它:)我有一个可绘制对象,可以获取 .png 照片,我可以用手势操作它。我还有一个 xml 布局,其中的背景图像应该位于该可绘制对象的后面。一切都发生在一个片段中。
当我运行代码并到达此片段时,会显示 png 并且手势可以工作,但是,没有膨胀的布局并且按下后退按钮时应用程序崩溃(我猜这是因为我在片段中使用 setContentView 所以有没有返回堆栈?我该如何避免这种情况?)。
稍后我将向场景添加其他图层。
我的问题是,我怎样才能用 xml 布局来膨胀片段,在它上面显示可绘制的,也许稍后在所有这些之上添加其他视图?
该片段的代码如下:
public class RoomFragment extends Fragment {
ViewGroup mRoot;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mRoot = (ViewGroup) inflater.inflate(R.layout.room_fragment, null);
/** Placing furniture .png element in SandboxView */
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.furniture);
View view = new SandboxView(this.getActivity(), bitmap);
this.getActivity().setContentView(view); // Replace with inflater?
return mRoot;
}}
Run Code Online (Sandbox Code Playgroud)
谢谢你!