调暗/模糊父布局背景

2023-12-26

这里有与上面主题相同的问题 但没有得到答案

我这里有一个布局

我需要在顶部布局中使用与底部布局相同的图像,但具有模糊样式

设置 alpha 没有帮助 - 文本视图也会影响

如何模糊向下布局的背景

此处为 XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:background="#ffffff">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="105"
        android:orientation="vertical">
/// top layout with  image 
        <LinearLayout
            android:background="@drawable/s"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="45">



        </LinearLayout>


        ////  other set of layouts that i want to add the same iamge but in blur style
        <LinearLayout
            android:alpha="220"

            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="60"
            android:weightSum="75"
            android:orientation="vertical">



            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="25">

<TextView
    android:id="@+id/brand_name"
    android:layout_marginTop="10dp"
    android:textSize="25dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="SHAKY ISLES"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

                <ImageView
                    android:id="@+id/image_icon"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:background="#000000"
                    android:layout_below="@+id/brand_name"
                    android:layout_centerHorizontal="true" />

                <TextView

                    android:text="  6 - 502 m"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBottom="@+id/image_icon"
                    android:layout_alignRight="@+id/brand_name"
                    android:layout_alignEnd="@+id/brand_name"
                    android:layout_below="@+id/brand_name" />

            </RelativeLayout>

            <RelativeLayout

                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="20">

                <TextView
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:id="@+id/discription"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="22, Customs St E ,Auckland and discription here.22, Customs St E ,Auckland and discription here.22, Customs St E ,Auckland and discription here.22, Customs St E ,Auckland and discription here.22, Customs St E ,Auckland and discription here.22, Customs St E ,Auckland and discription here. "
                    android:layout_centerVertical="true"
                    android:layout_centerHorizontal="true" />

                <View
                    android:id="@+id/boder"
                    android:layout_marginLeft="30dp"
                    android:layout_marginRight="30dp"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#000000"></View>




            </RelativeLayout>

            <RelativeLayout

                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="30"
               >

                <TextView
                    android:id="@+id/address"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="22, Customs St E ,Auckland"
                    android:layout_centerVertical="true"
                    android:layout_centerHorizontal="true" />

                <View
                    android:id="@+id/down_border"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="30dp"
                    android:layout_marginRight="30dp"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#000000"></View>

            </RelativeLayout>



        </LinearLayout>

    </LinearLayout>



</LinearLayout>

有什么帮助吗?

即使代码没有 xml


西萨拉先生模糊你的视野试试这个代码 为你做了一些编码

public class MainActivity extends Activity {
    private ImageView imViewAndroid;

    private TextView discriptionn;
    private TextView statusText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_layout);
        imViewAndroid = (ImageView) findViewById(R.id.image);

        discriptionn = (TextView) findViewById(R.id.discription);
        statusText = addStatusText((ViewGroup) findViewById(R.id.relative_layout_down));
        applyBlur();


    }

    private void applyBlur() {
        imViewAndroid.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                imViewAndroid.getViewTreeObserver().removeOnPreDrawListener(this);
                imViewAndroid.buildDrawingCache();

                Bitmap bmp = imViewAndroid.getDrawingCache();
                blur(bmp, discriptionn);
                return true;
            }
        });
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    private void blur(Bitmap bkg, View view) {
        long startMs = System.currentTimeMillis();

        float radius = 20;

        Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth()),
                (int) (view.getMeasuredHeight()), Bitmap.Config.ARGB_8888);

        Canvas canvas = new Canvas(overlay);

        canvas.translate(-view.getLeft(), -view.getTop());
        canvas.drawBitmap(bkg, 0, 0, null);

        RenderScript rs = RenderScript.create(MainActivity.this);

        Allocation overlayAlloc = Allocation.createFromBitmap(
                rs, overlay);

        ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(
                rs, overlayAlloc.getElement());

        blur.setInput(overlayAlloc);

        blur.setRadius(radius);

        blur.forEach(overlayAlloc);

        overlayAlloc.copyTo(overlay);

        view.setBackground(new BitmapDrawable(
                getResources(), overlay));

        rs.destroy();
        statusText.setText(System.currentTimeMillis() - startMs + "ms");
    }

    @Override
    public String toString() {
        return "RenderScript";
    }

    private TextView addStatusText(ViewGroup container) {
        TextView result = new TextView(MainActivity.this);
        result.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        result.setTextColor(0xFFFFFFFF);
        container.addView(result);
        return result;
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

调暗/模糊父布局背景 的相关文章

随机推荐

  • Xcode 4 idekeybounds 一次击键可绑定多个命令

    拼命尝试自定义 Xcode 4 键绑定 我正在编辑用户 idekeybindings 文件 当打开时修改该文件 然后随后尝试通过键绑定界面进行更新时 xcode 有时会擦除该文件 可爱 我的理解是 提供一个命令 选择器 而不是仅仅一个字符串
  • bash:nano:在 Windows git bash 中找不到命令

    我在 Windows 电脑上使用 git 版本 2 7 0 windows 1 我使用了以下命令 nano README 结果我 bash nano command not found 现在如何将 Nano 文本编辑器安装到 git bas
  • 理解 main 的一个不常见的参数

    以下问题是在大学编程竞赛中给出的 我们被要求猜测输出和 或解释其工作原理 不用说 我们都没有成功 main write read 0 1 main 一些简短的谷歌搜索让我找到了这个确切的问题 在codegolf stackexchange
  • 正则表达式的含义如 - \\d , \\D, ^ , $ 等 [重复]

    这个问题在这里已经有答案了 这些表达的意思是什么 我在哪里可以了解它们的用法 d D s S w W t n etc 我需要使用stringr包 我完全不知道如何使用这些 From regexp 在里面扩展正则表达式部分 插入符号 和美元符
  • 子查询上的 Groupwise MAX()

    我正在尝试计算返回表中的最大值以及该表中的其他值 然而 我正在执行此操作的表不是 真正的 表 它是由子查询生成的表 这给我带来了问题 因为我认为在不重新指定整个子查询的情况下我无法连接它两次 我目前有一个 SQL Server 解决方案 使
  • React中继injectNetworkLayer不是一个函数

    我正在遵循 lynda 的教程 构建和部署全栈 React 应用程序 在 注入中继网络层 一章中 在index js中 尝试设置网络层 程序编译成功 但我在浏览器中收到以下错误 类型错误 WEBPACK IMPORTED MODULE 4
  • com.google.cloud.pubsub.spi.v1.Publisher.publish 未将数据发送到 PubSub

    对新版本的调用com google cloud pubsub spi v1 Publisher publish pubsubMessage get 永远挂着 我不确定问题是什么 代码片段 com google cloud pubsub sp
  • Dialogflow,从音频中检测意图

    我正在尝试将音频文件发送到对话流 API 进行意图检测 我已经有一个工作得很好的代理 但只能处理文本 我正在尝试添加音频功能 但没有成功 我正在使用此页面中提供的示例 Java https cloud google com dialogfl
  • Visual Studio 2017 中的 SSIS 工具箱缺少某些组件

    我在用Visual Studio Community 2017用于开发 SSIS 包 我使用 SQL Server 2016 某些组件不在 SSIS 工具箱中 这就是我现在拥有的 这是我的大学所拥有的 他们没有与我相同版本的 Visual
  • 如何在 Excel 中使用 VBA 从 SQLite 数据库检索数据?

    我正在使用 ADO 从 VBA 连接到 db 文件 遵循此问题的答案question https stackoverflow com questions 42509154 accessing a sqlite database in vba
  • 无法更改 Visual Studio 代码设置

    我尝试更改 Visual Studio 代码设置 但无法编辑任何内容 我应该怎么办 我想将编码设置为 files encoding ISO 8859 1 这些是我使用的步骤 1 Ctrl Shift p 打开命令面板2 搜索设置并单击首选项
  • onPrepareOptionsMenu 切换菜单项时如何刷新 ActionBar?

    在我的应用程序中 我经常启用 禁用菜单条目 并让它们从 onPrepareOptionsMenu 中可见 今天 我开始向我的一些 Android 2 x 应用程序添加 android showAsAction 菜单属性 以显示 Action
  • Grails 服务器发送事件

    我需要让服务器发送事件与 Grails 一起工作 我觉得我已经很接近了 但只是还不够 JavaScript 请求成功到达控制器 但每次都会抛出错误 它每隔 2 秒左右重试一次 可能是由于错误 当服务器的会话计时器低于 5 分钟时 我需要向用
  • CFML 使用哪个版本的 Hibernate?

    The 休眠文档 http hibernate org orm documentation 有时指不同版本之间的差异 ColdFusion 10 使用哪些版本的 Hibernate ColdFusion 9 中也是这样吗 Railo 稳定版
  • 无法使用 Nest.js 设置 cookie

    我创造了 sign in端点基本上返回带有 2 个令牌的对象 刷新令牌和访问令牌 Post sign in signIn Body signInUserDto SignInUserDto Promise
  • 使用 ASP.NET (C#) 在页面之间传递变量,而不使用 QueryString

    寻求有关在不使用 QueryString 的情况下在页面之间传递变量的建议 诸如 Google 之类的网络爬虫会捕获 URL 中的查询字符串 我正试图摆脱使用它 是否有另一种建议的方法来传递变量 我考虑过使用会话变量 但这只是为了简单地将变
  • VS2010 和 VS2012 之间的二进制 C++ 库兼容性?

    我对 VS2010 和 VS2012 之间编译库的二进制兼容性感到困惑 我想迁移到 VS2012 但是许多闭源二进制 SDK 仅适用于 VS2010 例如用于连接硬件设备的 SDK 传统上 据我所知 Visual Studio 对编译器版本
  • 根据 python pandas 中的行值合并两个数据框

    我在 pandas 中有两个数据框 如下所示 df1 df2 Column1 Column2 Column3 ColumnA ColumnB ColumnC 0 a x x 0 c y y 1 c x x 1 e z z 2 e x x 2
  • BigInteger.valueOf() 对于非常大的数字?

    在 Java 中将 50 位字符串转换为 BigInteger 的最佳方法是什么 它没有 valueOf String 方法 而且我无法转换为 Long 因为它太小了 它确实有一个BigInteger String http java su
  • 调暗/模糊父布局背景

    这里有与上面主题相同的问题 但没有得到答案 我这里有一个布局 我需要在顶部布局中使用与底部布局相同的图像 但具有模糊样式 设置 alpha 没有帮助 文本视图也会影响 如何模糊向下布局的背景 此处为 XML