java - How to fill page with overlay -
i have transparent
overlay in android
app when user click on it,it fade can't fill activity below image
mainactivity :
<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" tools:context=".mainactivity" > <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:text="this original view" /> </relativelayout>
overlayactivity :
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <imageview android:id="@+id/over_lay_image" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#50220000" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="30dp" android:text="this overlay view" /> </relativelayout>
java :
public class mainactivity extends activity { private imageview moverlayimage; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); final dialog overlayinfo = new dialog(mainactivity.this); overlayinfo.requestwindowfeature(window.feature_no_title); overlayinfo.getwindow().setbackgrounddrawable(new colordrawable(color.transparent)); overlayinfo.getwindow().clearflags(windowmanager.layoutparams.flag_dim_behind); overlayinfo.setcontentview(r.layout.overlay_view); overlayinfo.show(); moverlayimage = (imageview) overlayinfo.findviewbyid(r.id.over_lay_image); moverlayimage.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub overlayinfo.cancel(); } }); } }
delete overlay activity, , inside main activity apply code :
<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" tools:context=".mainactivity" > <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:text="this original view" /> <!-- overlay --> <relativelayout android:id="@+id/over_lay_page" android:layout_width="match_parent" android:layout_height="match_parent" > <imageview android:id="@+id/over_lay_image" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#50220000" android:onclick="clickedoverlay" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="30dp" android:text="this overlay view" /> </relativelayout> </relativelayout>
note added line on imageview
runs function when clicked, on java file add function:
//the onclick on xml requires function of signature void(view) clicked view (in case imageview) public void clickedoverlay(view view) { //imageview clicked relativelayout rllayout = (relativelayout) findviewbyid(r.id.over_lay_page); rllayout.setvisibility(view.gone); }
this make relativelayout
contains overlay views (including imageview
clicked) not invisible not interfere anything. ignores input it.
in case misunderstood question feel free correct me (i'm not sure understood completely).
also if want fade in or out or can alphaanimation
.
Comments
Post a Comment