Ajouter semi-transparente superposition de l'activité de fond au moment de l'exécution
J'ai une application que j'ai mis en arrière-plan d'une image à partir de xml. J'obtiens l'affichage en appelant
setContentView(R.)
.
Comment puis-je placer un semi-transparente superposition sur cette toile de fond au moment de l'exécution en fonction d'une condition. Je voudrais avoir une incrustation rouge avec son alpha fixé à 50%.
J'ai essayé de créer un autre fichier xml avec le point de vue de reproduire et de l'image/de superposition, mais son désordre que j'ai pour gonfler tous les boutons/textview lorsque j'utilise le nouveau point de vue.
merci matt
[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);
}
- Si vous savez comment opaque vous voulez qu'il soit, pourquoi pas un PNG? Ce sera juste une image que vous pouvez ajouter à la mise en page, chaque fois que nécessaire.
Vous devez vous connecter pour publier un commentaire.
Sur le dessus de ma tête, vous pouvez déclarer la couleur d'arrière-plan, y compris alpha composant dans un fichier de ressources (c'est à dire colors.xml)
Et puis mettre une vue (c'est à dire
RelativeLayout
), au-dessus du reste de la vue.-Tout ce que vous devez faire est de changer la visibilité de R. id.transparentOverlay que vous le désirez.
over
le drawable, vous avez réellement besoin de le mettreunder
dans votre xml. Il suffit de déplacertransparentOverlay
entre lesLinearLayout
avec l'arrière-plan et la prochainetextviewcompanyname
.@color
au lieu d'un@drawable
, comme c'est le plus polyvalent; vous pouvez modifier dynamiquement les@color
la valeur et la transparence, et vous économiser de la ressource espace de la png drawable. De toute façon, si vous n'êtes pas à changer de couleur ni de transparence, votre approche est parfaitement bien pour moi.