调暗/模糊父版面设计背景 [英] dim/blur a parent layout background

查看:105
本文介绍了调暗/模糊父版面设计背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

there are questions here same as the above topic but didn't get an answer

我在这里有一个布局

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

i need to use the image as the same in top layout for bottom one but with blur style

设置Alpha值无济于事-文本视图也会影响

set alpha does not help - text views also affect

如何模糊向下布局的背景

how to blur the background of the down layout

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的代码

推荐答案

先生. sisara使您的视图模糊尝试此代码 为您做了一些编码

Mr. sisara to blur your view try this code did some coding for you

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;
    }
}

这篇关于调暗/模糊父版面设计背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆