![](/img/trans.png)
[英]Android Studio - How can I generate a new textview on my linear layout every time i click a button
[英]How can i Blur the background of my textview in android studio
我在其顶部有一个带有textview的图像。 我想知道如何模糊文本视图的背景(仅图像的一部分)以使其更具可读性。 我曾尝试查看模糊库,但似乎只能模糊整个图片。
当您想使textview位于imageview上方时,使其更具可读性。 要做到这一点而不是使图像模糊,为什么不使用渐变可绘制或彩色。
我对我的应用程序有相同的要求,我只是将渐变视图放在ImageView的一部分上。
我们开工吧
第1步:创建一个渐变形状并将其放在drawable文件夹下,假设形状名称为gradient_overlay.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:endColor="#00000000"
android:startColor="#BB000000"/>
</shape>
步骤2:创建一个虚拟视图,并将其放置在ImageView或ImageView的一部分上。
<View
android:id="+@id/gradientView"
android:layout_width="match_parent"
android:layout_height="60dp" // adjust the height
android:layout_alignBottom="@id/picture" // give the id of your image
android:background="@drawable/gradient_overlay">
</View>
第3步:然后将您的textview对准gradientView。 使文本正确可见。
添加此自定义BlurView解决方案: https : //github.com/mmin18/RealtimeBlurView
然后将您的BlurView放在布局中TextView的后面:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<com.github.mmin18.widget.RealtimeBlurView
android:id="@+id/textview_blurview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/my_textview"
android:layout_alignBottom="@+id/my_textview"
android:layout_alignStart="@+id/my_textview"
android:layout_alignLeft="@+id/my_textview"
android:layout_alignEnd="@+id/my_textview"
android:layout_alignRight="@+id/my_textview"/>
<TextView
android:id="@+id/my_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text in front of blur view"/>
</RelativeLayout>
最后,根据需要在代码中设置模糊和颜色
blurView.setBlurRadius(80.0f);
blurView.setOverlayColor(R.color.background_blur_color);
您可以使用框架布局产生模糊效果,框架布局允许沿z轴对齐视图,最后一个子项出现在所有其他子项上方,用法示例:-
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView android:layout_width="match_parent"
android:layout_gravity="top"
android:layout_height="200dp"/>
<TextView
android:layout_width="match_parent"
android:background="#10000000"
android:layout_gravity="bottom"
android:layout_height="100dp" />
<TextView
android:layout_width="wrap_content"
android:text="Text Here"
android:layout_marginBottom="50dp"
android:layout_gravity="bottom|center_horizontal"
android:layout_height="wrap_content" />
</FrameLayout>
您还可以将文本视图背景设置为较低的aplha(AA <“ FF”-> max alpha)的某种颜色(#AARRGGBB),以轻松再现相似的效果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.