小编Chr*_*rch的帖子

Android Fragment返回堆栈的问题

我对android片段后台堆栈的工作方式存在很大的问题,并且非常感谢所提供的任何帮助.

想象一下,你有3个碎片

[1] [2] [3]

我希望用户能够[1] > [2] > [3]在返回的路上导航(按下后退按钮)[3] > [1].

正如我想象的那样,这将通过addToBackStack(..)在创建将片段[2]带入XML中定义的片段持有者的事务时不调用来实现.

这样的现实似乎如果我不想[2]再次出现当用户按下按钮时[3],我不能addToBackStack在显示片段的事务中调用[3].这似乎完全违反直觉(可能来自iOS世界).

无论如何,如果我这样做,当我离开[1] > [2]并按回来时,我会按[1]预期返回.

如果我去[1] > [2] > [3],然后按回我跳回[1](如预期的那样).现在,当我尝试[2]再次跳转时,会发生奇怪的行为[1].首先[3]是在[2]进入视图之前简要显示.如果我在此时按回按钮[3],如果我再次按回来,则退出该应用程序.

任何人都可以帮我理解这里发生的事情吗?


这是我的主要活动的布局xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical" >

<fragment
        android:id="@+id/headerFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        class="com.fragment_test.FragmentControls" >
    <!-- Preview: layout=@layout/details -->
</fragment>
<FrameLayout
        android:id="@+id/detailFragment" …
Run Code Online (Sandbox Code Playgroud)

android android-fragments back-stack

119
推荐指数
5
解决办法
13万
查看次数

Android PCM到Ulaw编码wav文件

我正在尝试将原始pcm数据编码为uLaw,以节省传输语音数据所需的带宽.

我在这个页面上遇到了一个名为UlawEncoderInputStream的类,但是没有文档!:(

构造函数接受输入流和max pcm值(无论是什么).

  /**
     * Create an InputStream which takes 16 bit pcm data and produces ulaw data.
     * @param in InputStream containing 16 bit pcm data.
     * @param max pcm value corresponding to maximum ulaw value.
     */
    public UlawEncoderInputStream(InputStream in, int max) {
Run Code Online (Sandbox Code Playgroud)

查看代码后,我怀疑我应该使用提供的函数计算这个"max"值:maxAbsPcm.问题是,我真的不明白我的意思是要传递给它!我正在将原始pcm记录到SD卡上的文件中,因此我没有一个连续的内存驻留数据块传递给它.

  /**
     * Compute the maximum of the absolute value of the pcm samples.
     * The return value can be used to set ulaw encoder scaling.
     * @param pcmBuf …
Run Code Online (Sandbox Code Playgroud)

java encoding android pcm

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

自定义UIView中的UICollectionView

我正在尝试使用UICollectionView制作自定义工具栏。

我想子类化UIView并将集合视图作为子子视图。

我使用的是标准流程布局,如果将集合视图添加到视图控制器中,则一切工作正常。

当我将UICollectionview添加到MY子类视图时,所有这些都将停止正常工作。这些项目首先出现在视图外部,我必须向下滚动才能看到它们。项目开始之前似乎要添加一行空白。

当我在UIView子类内的collectionview上调用contentSize时,由于某种原因它会返回-20的高度。

我将工具集实例指向直接在视图控制器视图中托管的CollectionView的数据源,这样就可以排除代码差异。我在想,我可能会错过一些与UIView生命周期事件有关的细微问题?

在此处输入图片说明

这是代码:

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}


-(void)updateConstraints
{

    [super updateConstraints];

    UIView* view = _collectionView;


    [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:view.superview attribute:NSLayoutAttributeTop multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:view.superview attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];

    [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:view.superview attribute:NSLayoutAttributeLeading multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:view.superview attribute:NSLayoutAttributeTrailing multiplier:1 constant:0]];
}

-(void)layoutSubviews
{
    [super layoutSubviews];

    [_collectionView reloadData];
}

+(BOOL)requiresConstraintBasedLayout
{
    return YES; …
Run Code Online (Sandbox Code Playgroud)

objective-c uiview ios uicollectionview

5
推荐指数
0
解决办法
1214
查看次数