2013-10-23 10 views
9

Ich habe eine enthält 2 LinearLayouts einer von ihnen deckt teilweise die andere. Ich möchte den Teil der LinearLayout oben transparent machen, so dass ich auch die 2. LinearLayoutwissen, dass ich 2 Bilder als Hintergrund für die 2 LinearLayouts.Wie wird ein linearLayout in Android teilweise transparent gemacht?

+0

also wollen Sie den abgedeckten Teil des Layouts 1, der teilweise Layout 2 bedeckt, transparent? – johntheripp3r

+0

@ user2137817 können Sie Ihren Layoutcode eingeben? Ich brauche das Gleiche, was du gepostet hast. – ydnas

Antwort

41

Als wir die Farbe, es ist wie ARGB (Alpha Red Green Blue).Sie müssen die Alpha in dem Farbcode Änderung der Menge an Transparenz zu erhöhen oder zu verringern: kann

Sie es von 00 bis FF (Hexadezimal)

Für maximale Transparenz im Bereich = > # 00555555 (Hier steht für die alpha)

für minimale oder keine Transparenz => # FF555555 (Hier FF für die Alpha steht)

So für die Einstellung Transparenz eines Image Sie so codieren können:

ImageView image = (ImageView) findViewById(R.id.myImage); 
image.setAlpha(0.3); 

Auch können Sie die Alpha für Ihren Linearlayout eingestellt wie diese:

LinearLayout ll = (LinearLayout) findViewById(R.id.linearlayout); 
ll.setAlpha(0.4); 
+0

bearbeitet meine Frage – user2137817

+0

Das Problem ist, wenn ich das Alpha für eine linealayout ändern, werden die Kinder auch transparent sein und ich will das nicht – user2137817

+0

Dann machen Sie Ihre LinearLayout transparent. Fügen Sie dann ein ImageView hinzu und steuern Sie die Transparenz dieses ImageView. – Arshu

9

Machen Sie Ihren LinearLayout Hintergrund Transparent:

android:background="@android:color/transparent" 

und Ihr Layout teilweise transparent für die Herstellung vielleicht dieser Link Helfen Sie: How to create View partially invisible

Edit:, wenn Sie ein Bild als Hintergrund des Layouts haben so Ich denke, dass Sie Alpha für Ihr LinearLayout einstellen und es vom Code steuern können, ohne Ihren Hintergrund zu ändern, um Ihr Layout mit Hintergrundbild transparent zu machen:

android:alpha="" 

alpha property of the view, as a value between 0 (completely 
transparent) and 1 (completely opaque) 
10

Verwenden Sie diese in Ihrem Layout

android:alpha="0.5" 

0,0 ist völlig transparent, 1,0 vollständig undurchsichtig ist.

+0

Warum musste ich eine halbe Stunde lang nach einer Antwort suchen? So verdammt simpel und doch affektiv, nett! –

+0

Nun, das hat nicht lange gedauert .. es ist auf Build-Time mit: "String Typen nicht erlaubt (bei 'Alpha' mit Wert '0.5f')." –

+1

Verwenden Sie es einfach wie 'android: alpha =" 0.5 "' – Patosai

1

Set-Top-Linear-Layouts des Hintergrund als

background = "# CCFFFFFF" in Ihrer layout.xml Datei

Änderung Alpha-Modus für mehr Transparenz hier "CC".

("00" als voll transparent)

https://stackoverflow.com/a/4990254/665561

3

Es ist so spät, aber es wird hilfreich sein, gehen für andere ....

erstellen xml-Datei wie folgt ...

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    > 

    <LinearLayout 
     android:id="@+id/l1" 
     android:layout_width="190dp" 
     android:layout_height="match_parent" 
     android:background="#234234" 
     android:orientation="vertical" > 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="onClickNext" 
     android:text="Next >" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/l2" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:alpha=".05" 
     android:orientation="vertical" > 
     </LinearLayout> 

</LinearLayout> 

jetzt Ihr Manifest ... und fügen diese Linie ...

<activity android:name=".Activity" 
     android:theme="@android:style/Theme.Translucent"> 

enjoyyyy ...

1

die Hintergrundfarbe wie folgt aus:

android: background = "# 00FFFFFF"

0

das Thema auf die Aktivität hinzufügen, die in Ihrer Manifest-Datei transparent sein muss.

<activity android:name=".YourActivity" 
    android:theme="@android:style/Theme.Translucent"> 
    </activity> 
Verwandte Themen