SK9*_*SK9 118 xml android alpha android-layout android-imageview
是否真的没有XML属性对应setAlpha(int)
?
如果没有,有什么替代品?
jfc*_*ato 227
它比其他响应更容易.有一个xml值alpha
,它取双倍值.
android:alpha="0.0"
那是看不见的
android:alpha="0.5"
透视
android:alpha="1.0"
完全可见
这就是它的工作原理.
ssc*_*rth 175
没有,没有,怎么看"相关的XML属性"部分丢失了在ImageView.setAlpha(INT)文档.另一种方法是使用View.setAlpha(浮点),其XML对方是android:alpha
.它需要0.0到1.0的范围而不是0到255.例如,使用它
<ImageView android:alpha="0.4">
Run Code Online (Sandbox Code Playgroud)
但是,后者仅在API级别11之后可用.
Ume*_*esh 47
我不确定XML,但您可以通过以下方式执行代码.
ImageView myImageView = new ImageView(this);
myImageView.setAlpha(xxx);
Run Code Online (Sandbox Code Playgroud)
在API 11之前:
在API 11+中:
mar*_*ish 13
也许是纯色背景的有用替代方案:
将LinearLayout放在ImageView上,并使用LinearLayout作为不透明度过滤器.下面是一个黑色背景的小例子:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF000000" >
<RelativeLayout
android:id="@+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_stop_big" />
<LinearLayout
android:id="@+id/opacityFilter"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#CC000000"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
在#00000000(完全透明)和#FF000000(完全不透明)之间改变LinearLayout的android:background属性.
现在有一个XML替代方案:
<ImageView
android:id="@+id/example"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/example"
android:alpha="0.7" />
Run Code Online (Sandbox Code Playgroud)
它是:android:alpha ="0.7"
值为0(透明)到1(不透明).
归档时间: |
|
查看次数: |
197379 次 |
最近记录: |