2016-06-12 43 views
0

我想给阿尔法只包含textview的相对布局,但它给阿尔法它的孩子现在textview也有阿尔法也没有给我任何东西我想删除alpha,并且只留下相对布局阿尔法布局让所有的孩子都有阿尔法?Android

 <?xml version="1.0" encoding="utf-8"?> 
      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/phaseLayout" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" > 

       <ImageView 
        android:id="@+id/phaseImage" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" 
        android:layout_centerHorizontal="true" 
        android:scaleType="fitXY" 
        android:src="@drawable/pic1" /> 

       <FrameLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignBottom="@+id/phaseImage" 
        android:layout_alignParentRight="true" 
        android:alpha=".6" 
         android:background="@drawable/text_view_border" 
        android:layout_marginBottom="10dp" > 

        <RelativeLayout 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 

         android:gravity="center_vertical" 
         android:padding="5dp" > 

         <TextView 
          android:id="@+id/phaseName" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_centerVertical="true" 
          android:padding="5dp" 
          android:text="" 
          android:textAppearance="?android:attr/textAppearanceMedium" 
          android:textColor="@color/white" /> 
        </RelativeLayout> 
       </FrameLayout> 

      </RelativeLayout> 
+0

那么,孩子从他们的父母继承。你期望什么?现在循环所有的孩子,并单独设置他们的alpha。 – 2016-06-12 11:26:40

+0

我做了男人,但没有工作,我需要让textview有alpha。6的黑色背景我试了这么多,没有工作:( –

+0

但为什么你需要设置父母的alpha? – 2016-06-12 11:37:05

回答

1

使用RelativeLayout的背景并设置drawable的透明颜色。 绘制例如:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <solid android:color="#00FFFFFF" /> 
</shape> 
+0

你的解决方案也很好,谢谢你:) –

1

使用阿尔法属性到你的布局将导致申请阿尔法所有子布局和视图。更好的方法是将Alpha应用于给定布局的背景。这将导致仅将Alpha应用于该布局。

下面是映射:

Hex Opacity Values 

100% — FF 
95% — F2 
90% — E6 
85% — D9 
80% — CC 
75% — BF 
70% — B3 
65% — A6 
60% — 99 
55% — 8C 
50% — 80 
45% — 73 
40% — 66 
35% — 59 
30% — 4D 
25% — 40 
20% — 33 
15% — 26 
10% — 1A 
5% — 0D 
0% — 00 

所以,如果你的颜色代码为#FFFFFF那么你的颜色代码将#99FFFFFF指白色与60%的透明度。

希望它会帮助你:)

+0

非常题外话。 OP没有询问如何设置alpha。但为什么alpha从父母继承到儿童。 – 2016-06-12 11:41:25

+0

真的非常感谢这么多惊人的解决方案<3 –