2016-05-27 351 views
-1

我有RelativeLayoutProgressBar我想设置RelativeLayout透明,使用android:background="@null"。它运行良好,但不适用于android 5.1.0及更高版本。Android RelativeLayout设置透明

这里的file.xml

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@null"> 
    <ProgressBar style="@style/progress_bar_style"/> 
</RelativeLayout> 

所以,我已经试过像

android:background="#00000000" 
android:background="#77000000" 
android:background="#AARRGGBB" 

e.t.c我在计算器已经找到了一些方法。 那么,如何解决这个问题呢?

UPDATE:

The trouble's image

+0

,'RelativeLayout'的颜色是什么? –

+0

这是完全不同的布局吗? –

+0

你为什么不使用alpha? –

回答

1

你的下面的代码是在阿比工作正常> 21

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@null"> 
    <ProgressBar style="@style/progress_bar_style"/> 
</RelativeLayout> 

更新:

你必须clean项目和rebuild它。愿这能起作用。

+0

如果我设置阿尔法我的布局它改变我的进度条,而不是布局的透明度。也许我需要添加一个布局,并在那里做一些魔术。会尝试 – pligosv

+0

@pligosv你的代码工作正常,你可以干脆'重建'你的项目可能是工作。 – Ironman

+0

@pligosv看到我更新的答案。 – Ironman

-1

我面对一些日子同样的问题 ü可以给颜色与Java代码的RelativeLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:id="@+id/rlayout"> 

在Java文件你给colro

RelativeLayout ln = (RelativeLayout) findViewById(R.id.rlayout); 
    ln.setBackgroundColor(Color.TRANSPARENT); 
-1

争取你的RelativeLayout背景设置:

android:background="@android:color/transparent" 
-1
<RelativeLayout 
    android:id="@+id/yourRelativeLayoutID" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/bg_relative"> 

在您的颜色中添加bg_relative颜色。XML

<color name="bg_relative">#80795548</color> 

and here 80 is transparency code, you can change like following, 

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

'android 5.1.0及更高版本'中的
+0

试过,没有帮助。 – pligosv