Is it matter if setting View alpha with alpha attribute or adding suitable value to background attribute?

huangapple 未分类评论48阅读模式
英文:

Is it matter if setting View alpha with alpha attribute or adding suitable value to background attribute?

问题

由于某种我无法理解的原因,当我想要将某个视图的不透明度设置为0.6时,所以当我设置以下代码时:

<View
    android:id="@+id/bottom_divider"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    android:background="#9903a9f4"/>

以及以下代码:

<View
    android:id="@+id/bottom_divider"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    android:background="#9903a9f4"
    android:alpha="0.6"/>

我得到了不同的颜色,虽然在十六进制背景的开头是99,但在0.6倍数中等于255。有人可以解释一下为什么在这两段代码中我得到了不同的颜色吗?

英文:

For some reason i can't understand when i want to set opacity of 0.6 to some view, so when i set the following code:

&lt;View
    android:id=&quot;@+id/bottom_divider&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_width=&quot;wrap_content&quot;
    app:layout_constraintLeft_toLeftOf=&quot;parent&quot;
    app:layout_constraintRight_toRightOf=&quot;parent&quot;
    app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
    android:background=&quot;#9903a9f4&quot;/&gt;

and the following code:

 android:id=&quot;@+id/bottom_divider&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_width=&quot;wrap_content&quot;
    app:layout_constraintLeft_toLeftOf=&quot;parent&quot;
    app:layout_constraintRight_toRightOf=&quot;parent&quot;
    app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
    android:background=&quot;#9903a9f4&quot;
    android:alpha=&quot;0.6&quot;/&gt;

i get a different colour , ** althugh** 99 in the beginning of the background in hexa is equal to 255 multiple in 0.6
can someone explain me why i get different colours in both codes?

huangapple
  • 本文由 发表于 2020年5月4日 18:01:12
  • 转载请务必保留本文链接:https://java.coder-hub.com/61589601.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定