How to make a linearLayout partially transparent in android?

前端 未结 7 1748
刺人心
刺人心 2021-01-31 04:01

I have a RelativeLayout containing 2 LinearLayouts one of them is partially covering the other. I want to make the part of the LinearLayout

相关标签:
7条回答
  • 2021-01-31 04:38

    Add the theme to the activity which needs to be transparent in your Manifest file.

        <activity android:name=".YourActivity"
         android:theme="@android:style/Theme.Translucent">
       </activity>
    
    0 讨论(0)
  • 2021-01-31 04:39

    When we set the color it is like ARGB(Alpha Red Green Blue). You need to change the alpha in the color code to increase or decrease the amount of Transparency :

    You can range it from 00 to FF (Hexa Decimal)

    For maximum transparency => #00555555 (Here 00 stands for the alpha)

    For minimum or no transparency => #FF555555 (Here FF stands for the alpha)

    So, for setting the transparency of an ImageView you can code like this:

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

    Also, you can set the alpha for your LinearLayout like this :

    LinearLayout ll = (LinearLayout) findViewById(R.id.linearlayout);
    ll.setAlpha(0.4);
    
    0 讨论(0)
  • 2021-01-31 04:39

    Use this in your Layout

    android:alpha="0.5"
    

    0.0 is totally transparent, 1.0 is fully opaque.

    0 讨论(0)
  • 2021-01-31 04:44

    set the background color like this:

    android:background="#00ffffff"

    0 讨论(0)
  • 2021-01-31 04:45

    It is so late but it will be helpful for others....

    create xml file like this...

      <?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>
    

    now go to your manifest... and add this line...

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

    enjoyyyy...

    0 讨论(0)
  • 2021-01-31 04:53

    Make your LinearLayout Background Transparent :

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

    and for making your Layout Partially Transparent maybe this Link Helps you : How to create View partially invisible

    Edit: if you have an Image as Background of your layout so i think you can set alpha for your LinearLayout and control it from code without changing your background, to Transparent your Layout with Background Image :

    android:alpha=""
    
    alpha property of the view, as a value between 0 (completely 
    transparent) and 1 (completely opaque)
    
    0 讨论(0)
提交回复
热议问题