2013-09-27 10 views
5

पर गतिविधि backround के लिए अर्द्ध पारदर्शी ओवरले जोड़ें मैं एक ऐप्लिकेशन है जो मैं एक्सएमएल से एक छवि के लिए पृष्ठभूमि सेट है। मुझेक्रम

setContentView(R.) 

पर कॉल करके दृश्य प्राप्त होता है। मैं इस स्थिति पर एक शर्त के आधार पर रनटाइम पर अर्ध-पारदर्शी ओवरले कैसे रख सकता हूं। मैं अपने अल्फा सेट के साथ 50% तक लाल ओवरले रखना चाहता हूं।

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

धन्यवाद

[edit1]

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

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<LinearLayout android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/carefreebgscaledlighting" 
    android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> 


    <TextView 
     android:id="@+id/textviewcompanyname" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#003F87" /> 

    <TextView 
     android:id="@+id/textViewYouAreSignedIn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_alignParentTop="true" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#003F87" 
     /> 

      <TextView 
     android:id="@+id/textViewUnsentTransactions" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_below="@id/textViewYouAreSignedIn" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#003F87" 
     /> 

[EDIT2]

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


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 


    <RelativeLayout 
     android:id="@+id/transparentOverlay" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@color/red_transparent" > 


<LinearLayout android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/carefreebgscaledlighting" 
    android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> 




    <TextView 
     android:id="@+id/textviewcompanyname" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#003F87" /> 

    <TextView 
     android:id="@+id/textViewYouAreSignedIn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_alignParentTop="true" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#003F87" 
     /> 

[edit3]

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


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 



<LinearLayout 
    android:id="@+id/ll1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/carefreebgscaledlighting" 
    android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> 




    <TextView 
     android:id="@+id/textviewcompanyname" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#003F87" /> 

मैट।

if(status.equalsIgnoreCase(IN)){ 

       youAreSignedInAt.setText("You are signed in at " + name); 
       LinearLayout layout =(LinearLayout)findViewById(R.id.ll1); 
       layout.setBackgroundResource(R.drawable.carefreebgscaledlightingred); 
      }else{ 

       youAreSignedInAt.setText("You are not signed in"); 
       LinearLayout layout =(LinearLayout)findViewById(R.id.ll1); 
       layout.setBackgroundResource(R.drawable.carefreebgscaledlighting); 
      } 
+0

आप जानते हैं कि कैसे अपारदर्शी आप इसे होना चाहते हैं, क्यों नहीं एक PNG? जब भी आवश्यक हो, यह केवल एक छवि होगी जिसे आप लेआउट में जोड़ सकते हैं। – Prmths

उत्तर

17

मेरे सिर के ऊपर बंद, आप एक संसाधन फ़ाइल में अल्फा घटक सहित पृष्ठभूमि रंग की घोषणा कर सकता है (यानी colors.xml)

<color name="red_transparent">#66FF0000</color> 

और फिर एक दृश्य डाल (यानी RelativeLayout), views.-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <!-- All your views --> 

    <!-- Transparent layer --> 
    <RelativeLayout 
     android:id="@+id/transparentOverlay" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/red_transparent" /> 

</RelativeLayout> 

आपको बस इतना करना R.id.transparentOverlay की दृश्यता बदल रहा है के रूप में आप की इच्छा की जरूरत के बाकी के ऊपर।

+0

हाय मैंने अपना एक्सएमएल पोस्ट किया है। जैसा कि आप देख सकते हैं कि मेरे पास पृष्ठभूमि के रूप में एक ड्रायबल सेट है। रन टाइम पर इस ड्रॉबल पर एक लाल रंग का टिंट रखना संभव है। क्या आपका कोड क्या करता है? धन्यवाद – turtleboy

+0

यदि आप चाहते हैं कि लाल ओवरले सब कुछ के शीर्ष पर है, जिसमें आपके ड्रॉइंग शामिल हैं, हां, यही मेरा स्निपेट करना है। यदि आप बस अपने ड्राइटेबल को लाल फ़िल्टर लागू करना चाहते हैं, तो यह एक पूरी कहानी है। – ssantos

+0

फिर भी, यदि आप ड्रॉइंग पर लाल ओवरले चाहते हैं, तो आप खींचने योग्य पर दृश्य के ऊपर @ + id/पारदर्शी ओवरले लेआउट डाल सकते हैं। – ssantos