2012-07-04 24 views
7

हाय मैं अपने सापेक्ष लेआउट के लिए अल्फा मान सेट करने की कोशिश कर रहा हूं, लेकिन मुझे यह मदद मिल रही है कि यह मेरी मदद कैसे करें .....मेरे सापेक्ष लेआउट के लिए अल्फा मान कैसे सेट करें?

मेरे पास मेरे xml लेआउट में तीन लेआउट पृष्ठभूमि 2 के लिए उपयोग कर रहा है पाद लेख के लिए हेडर 3 लेआउट के लिए लेआउट लेआउट। मैं अल्फा मान 2 & 3 लेआउट सेट करने के लिए तो मैं कई मायनों कोशिश कर रहा हूँ अभी भी मैं पता नहीं है इच्छा कृपया कैसे अल्फा मूल्य निर्धारित करने के लिए बता

एक्सएमएल कोड:

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

कोड:

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); 

    } 
} 

उत्तर

20

इस

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); 
+0

आपने मेरा दिन बनाया! – gibffe

8

RelativeLay कोशिश बाहर आरएल; ...
rl.setAlpha (0.5F);

<RelativeLayout 
    android:id="@+id/rl" 
    android:layout_width="200dp" 
    android:layout_height="200dp" 
    android:background="@drawable/bg" 
    android:alpha="0.5"> 
+0

rl.setAlpha को एपीआई> = 11 – Darpan

+0

की आवश्यकता है यह पूरे लेआउट को पारदर्शी बनाता है, न केवल पृष्ठभूमि छवि, ऐसा लगता है। मेरे पास बटन और टेक्स्टव्यू जैसे कुछ दृश्य तत्व थे जो इस अल्फा मान को भी लेते थे जब मैंने इसे रूट रिलेवेटिवआउट में जोड़ा। –

0

इन मामलों मैं आम तौर पर एक ही समय में रंग और अल्फा सेट करना चाहते हैं के लिए करते हैं में, तो मैं बस rl.setBackgroundColor(0xAACCCCCC); जहां एक अल्फा मूल्य है का उपयोग करें और सी रंग है, हेक्स प्रारूप में।

उदाहरण: 0 पारदर्शी काला पृष्ठभूमि के लिए rl.setBackgroundColor(0x88000000);

या एक्सएमएल में: android:background="#88000000"

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^