Android——显示大图(背景虚化)的Activity

上效果图:

这里写图片描述

这个是一个Activity来展现的。

附代码:


public class ShowImgActivity extends BaseActivity {
    private ImageView iv ;
    private int WhichImg;
    private CommonDialog dialog;
    @Override
    public void initViews() {
        // TODO Auto-generated method stub

    }

    @Override
    public void initListeners() {
        // TODO Auto-generated method stub

    }

    @Override
    protected void onCreate(Bundle arg0) {
        // TODO Auto-generated method stub
        super.onCreate(arg0);
        initWindows();
        RelativeLayout layout=getLayoutView();
        setContentView(layout);


        WhichImg=getIntent().getIntExtra("img", 0);
        Bitmap bm=((BitmapDrawable) getResources().getDrawable(WhichImg)).getBitmap();
        iv.setImageBitmap(bm);

    }



    private void initWindows() {
        // TODO Auto-generated method stub
        //窗口对齐屏幕宽度
        Window win = this.getWindow();
        win.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.gravity = Gravity.TOP;//设置对话框置顶显示
        win.setAttributes(lp);
    }

    public RelativeLayout getLayoutView() {
        RelativeLayout v = new RelativeLayout(this);
        LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        v.setLayoutParams(lp);
        iv = new ImageView(this);
        LayoutParams ivlp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        iv.setLayoutParams(ivlp);
        v.addView(iv);
        return v;
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android Studio 中设置背景虚化,可以通过以下步骤实现: 1. 在布局文件中添加一个背景图片或颜色作为背景。 2. 在该布局文件中添加一个 ViewGroup,例如 FrameLayout。 3. 在该 ViewGroup 中添加要显示的内容。 4. 在布局文件中添加以下代码,将该 ViewGroup 设置为模糊背景: ``` <FrameLayout android:id="@+id/background" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/background_image" android:alpha="0.8" android:visibility="invisible"> <View android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent"/> </FrameLayout> ``` 5. 在 Activity 中找到该 ViewGroup,并使用 RenderScript 模糊背景,代码如下: ``` private void blurBackground() { final View backgroundView = findViewById(R.id.background); final View contentView = findViewById(R.id.content); final RenderScript rs = RenderScript.create(this); final Allocation input = Allocation.createFromBitmap(rs, getDrawingCache(backgroundView)); final Allocation output = Allocation.createTyped(rs, input.getType()); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setInput(input); script.setRadius(25); script.forEach(output); output.copyTo(getDrawingCache(contentView)); rs.destroy(); } private Bitmap getDrawingCache(View view) { view.setDrawingCacheEnabled(true); view.buildDrawingCache(); final Bitmap drawingCache = view.getDrawingCache(); if (drawingCache == null) { return Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); } else { return drawingCache; } } ``` 以上就是在 Android Studio 中设置背景虚化的步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值