Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set alpha value for my Relative layout?

Hi I'm trying to set alpha value for my relative layout but, i am getting error how to solve this help me.....

I have three layout in my xml layout 1st layout using for background 2nd layout using for header 3rd layout using for footer. I wish to set alpha value 2 & 3rd layout so i am trying many ways still i have no idea please tell how to set alpha value

xml code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:orientation="vertical" 
    android:background="@drawable/blue">

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="60px"
        android:orientation="horizontal"
        android:layout_alignParentTop="true"
        android:background="@drawable/gradient_black"
        android:id="@+id/ttest">
       <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

        />

        <TextView
            android:id="@+id/header_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="6dp"
            android:layout_toRightOf="@+id/imageView1"
            android:text="settings"
            android:textColor="@color/white"
            android:textSize="20sp" />

    </RelativeLayout>

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="55px"

        android:background="@drawable/gradient_black"
        android:gravity="bottom"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true" >
  <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ssss"
        />  

    </RelativeLayout>

</RelativeLayout>

code:

public class DesignActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        int width = getWindowManager().getDefaultDisplay().getWidth();
        int height = getWindowManager().getDefaultDisplay().getHeight();


        ImageView imgHead = (ImageView)findViewById(R.id.imageView1);

        ImageView imgbottom = (ImageView)findViewById(R.id.imageView2);


        imgbottom.setImageResource(R.drawable.back);
        imgbottom.setLayoutParams(new RelativeLayout.LayoutParams(width/8, height/8));


        imgHead.setImageResource(R.drawable.b);
        imgHead.setLayoutParams(new RelativeLayout.LayoutParams(width/8, height/8));
     //   RelativeLayout relative = (RelativeLayout)findViewById(R.id.ttest);

    }
}
like image 934
balaji Avatar asked Jul 04 '12 10:07

balaji


People also ask

Is linear or relative layout better?

LinearLayout is less used as compared to RelativeLayout. RelativeLayout is used more in applications. We can use LinearLayout inside RelativeLayout. We can also use RelativeLayout as a Child of LinearLayout.

How do you change opacity in XML?

How do you change opacity in xml? Create a drawable xml resource with bitmap as the root say bg. set android:src="@drawable/background" to the image which you want as the background. set android:alpha="0.4" to any value between 0 to 1 as per the required opacity.

What is relative and frame layout?

RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets. TableLayout : is a view that groups its child views into rows and columns. FrameLayout : is a placeholder on screen that is used to display a single ...


1 Answers

try this

AlphaAnimation alpha = new AlphaAnimation(0.5F, 0.5F);
alpha.setDuration(0); // Make animation instant
alpha.setFillAfter(true); // Tell it to persist after the animation ends
// And then on your layout
yourLayout.startAnimation(alpha);
like image 197
Manikandan Avatar answered Nov 13 '22 19:11

Manikandan