如何减少/增加布局的透明度而不是视图

时间:2013-02-20 08:44:24

标签: android android-layout relativelayout xml-layout

我想要这个。注意出现文本(即说明)的透明层。 还要检查背景木制背景。

enter image description here

我试过这个但没有得到理想的结果

 <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_margin="10dp"
                android:alpha="0.75" >

                <TextView
                    android:id="@+android:id/txtInstructions"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+android:id/relImagesLogo"
                    android:layout_centerInParent="true"
                    android:lineSpacingMultiplier="1.5"
                    android:text="Lorem Ipsum is simply dummy text of 

                    the printing and typesetting industry. Lorem Ipsum has been the 

                    industry&apos;s standard dummy text ever since the 1500s, when an                      unknown 

                    printer took a galley of type and scrambled it to make a type specimen 

                    book. It has survived not only five centuries, but also the leap into 

                    electronic typesetting, remaining essentially unchanged. It was popularised "
                    android:textColor="@android:color/white"
                    android:textSize="14sp" />

                <RelativeLayout
                    android:id="@+android:id/relImagesLogo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true" >

                    <ImageView
                        android:id="@+android:id/imgInstructionLogo"
                        android:layout_width="30dp"
                        android:layout_height="30dp"
                        android:layout_marginRight="2dp"
                        android:src="@drawable/instruction_icon" />

                    <ImageView
                        android:id="@+android:id/imgInstructionHeading"
                        android:layout_width="wrap_content"
                        android:layout_height="30dp"
                        android:layout_centerVertical="true"
                        android:layout_toRightOf="@+android:id/imgInstructionLogo"
                        android:src="@drawable/instruction_heading" />
                </RelativeLayout>
            </RelativeLayout>

请注意,此android:alpha="0.75"使我的所有观点对0.75级都透明。我不想要这个。我只想要那个透明的层。

知道我得到了这个结果

enter image description here

3 个答案:

答案 0 :(得分:2)


试试:

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_margin="10dp"
        android:background="#66FF0000" >

你可以看到:     机器人:颜色=&#34;#66FF0000&#34; //部分透明的红色

我想你检查这个信息: Android set alpha opacity for a custom view

Android and setting alpha for (image) view alpha

答案 1 :(得分:2)

您需要将最外层布局的背景设置为木质可绘制。 并将文本视图的背景设置为透明色。 试试这个:

<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:background="#FF008833" >

<TextView
    android:id="@+android:id/txtInstructions"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="30dp"
    android:layout_below="@+android:id/relImagesLogo"
    android:layout_centerInParent="true"
    android:lineSpacingMultiplier="1.5"
    android:background="#BB000000"

    android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&apos;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised "
    android:textColor="@android:color/white"
    android:textSize="14sp" />
</RelativeLayout>

答案 2 :(得分:1)

xxyyyyyy

xx是你的透明度级别,y是你的颜色。

xx max value是:ff //这是完全可见的

xx min值为:00 //这是完全不可见的

编辑:顺便说一下,我们在android中使用这些代码:background =“xxyyyyyy”