小编Ori*_*itm的帖子

Android:片段backStack

我试图在调用方法时加载一个新片段.此方法创建一个新片段并"替换"另一个片段:

private void showTestFragment(Fragment oldFragment, boolean addBackStack, BaseAdapter adapter, int position) {
    Cursor cursor = (Cursor)adapter.getItem(position);
    if(cursor != null){

        int idx = cursor.getColumnIndexOrThrow(Episode._ID);
        long rowId = cursor.getLong(idx);

        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        if(oldFragment != null){
            Log.i(TAG, "Removing the old fragment");
            fragmentTransaction.remove(oldFragment);
        }

        TestFragment testFragment =  new TestFragment();
        testFragment.setId(rowId);

        fragmentTransaction.add(android.R.id.content, testFragment);

        if(addBackStack){
            Log.i(TAG, "Added to the backstack");
            fragmentTransaction.addToBackStack(TAG);
        }

        fragmentTransaction.commit();
        Fragment f = getFragmentManager()
                .findFragmentById(R.id.index);
        Log.i(TAG, "after commit, frag is "+ f);
    }
}
Run Code Online (Sandbox Code Playgroud)

这很好,直到我回去.当我回去时,应删除最后一个片段.在我要实现活动方法之前

public void onBackPressed(){} …
Run Code Online (Sandbox Code Playgroud)

android android-fragments back-stack

38
推荐指数
1
解决办法
10万
查看次数

调整位图大小

下面的代码调整位图大小并保持宽高比.我想知道是否有更有效的调整大小的方法,因为我知道我正在编写已经在android API中可用的代码.

private Bitmap resizeImage(Bitmap bitmap, int newSize){
    int width = bitmap.getWidth();
    int height = bitmap.getHeight(); 

    int newWidth = 0;
    int newHeight = 0;

    if(width > height){
        newWidth = newSize;
        newHeight = (newSize * height)/width;
    } else if(width < height){
        newHeight = newSize;
        newWidth = (newSize * width)/height;
    } else if (width == height){
        newHeight = newSize;
        newWidth = newSize;
    }

    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;

    Matrix matrix = new Matrix(); …
Run Code Online (Sandbox Code Playgroud)

java android resize image bitmap

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

NSDate格式化程序

不幸的是,我尝试将字符串转换为NSDATE而没有运气.

2010年10月22日星期五,美国东部时间2010年11月26日

我知道格式化的选项(http://sree.cc/objective-c/nsdate-format-string-in-objective-c),但我不能让它工作.

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"???????"];
Run Code Online (Sandbox Code Playgroud)

任何人?

objective-c nsdate nsdateformatter

3
推荐指数
1
解决办法
1408
查看次数

iOS:块和ivars

在很多问题中,它被问到是否可以在块中使用self.答案是否定的,避免保留周期.

现在,当我在我的块中使用"ivar"时,UIViewController它应该没问题.但是当我使用时:

- (void)viewDidLoad
{
    [_customCell setChangedValueBlock:^{
        if(_object != nil){
            NSLog(@"This is a sample");
        }
    }];
}
Run Code Online (Sandbox Code Playgroud)

dealloc方法从未调用过:

-(void)dealloc{
    NSLog(@"Dealloc");
}
Run Code Online (Sandbox Code Playgroud)

当我删除时if(_object != nil){,dealloc调用该方法.

我应该_object在将它传递给块之前做弱引用吗?

objective-c ios objective-c-blocks retain-cycle

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

IOS:触摸外层图层,但在框架内部

我有一个UIView,它有一个可以接收触摸的图层掩码(小于它的帧).现在的问题是我想限制图层蒙版中的那些触摸.

蒙版是渲染的形状,并不总是矩形.

我必须这样做:

pointInside:withEvent:
Run Code Online (Sandbox Code Playgroud)

要么

hitTest:withEvent:
Run Code Online (Sandbox Code Playgroud)

或者有更好的解决方案吗?

mask uiview ios

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