我有一个自定义 listView,它是根据以下行项目布局构建的。我需要的是背景是半透明的。我可以按照下面的代码所示使用 Alpha 属性并将其设置为 0.5 来执行此操作。但是,这也使我的 textView 和 imageView 也变得半透明。
我怎样才能使背景颜色半透明,但文本和图像正常/不透明?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:background="#ffffff"
android:padding="8dp"
android:alpha="0.5">
<ImageView
android:id="@+id/Image"
android:layout_width="110dp"
android:layout_height="90dp"
android:layout_marginRight="6dip"/>
<LinearLayout
android:id="@+id/Text"
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent">
<TextView
android:id="@+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22dip"
android:textStyle="italic" />
<TextView
android:id="@+id/Text2"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="marquee"/>
</LinearLayout>
</LinearLayout>
最佳答案
尝试对背景使用 ARGB 值而不是使用 alpha。您可以使用 #80FFFFFF
将其设置为 50% 透明度。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:background="#80ffffff"
android:padding="8dp">
参见 this post
关于android - Xamarin android布局-行项目的透明背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26161811/