javascript - In wallpaper app i am getting Gap beside the image in fullScreenView -
plz @ below image getting gap beside image in full screen view plz please have on code , tell me what's wrong it.
if there solution plz explain me step-by-step (i new android)
package com.saveitornot.wallit;
fullscreenviewactivity.java
import android.annotation.suppresslint; import android.content.activitynotfoundexception; import android.content.intent; import android.content.pm.packagemanager; import android.graphics.bitmap; import android.graphics.point; import android.graphics.drawable.bitmapdrawable; import android.net.uri; import android.os.build; import android.os.bundle; import android.os.handler; import android.support.design.widget.coordinatorlayout; import android.support.v4.app.activitycompat; import android.support.v7.app.appcompatactivity; import android.util.log; import android.view.display; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.window; import android.view.windowmanager; import android.widget.imageview; import android.widget.linearlayout; import android.widget.progressbar; import android.widget.toast; import com.android.volley.request; import com.android.volley.response; import com.android.volley.volleyerror; import com.android.volley.toolbox.imageloader; import com.android.volley.toolbox.jsonobjectrequest; import com.saveitornot.wallit.app.appcontroller; import com.saveitornot.wallit.picasa.model.wallpaper; import com.saveitornot.wallit.utils.utils; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject; public class fullscreenviewactivity extends appcompatactivity implements view.onclicklistener { private static final string tag = fullscreenviewactivity.class .getsimplename(); public static final string tag_sel_image = "selectedimage"; private wallpaper selectedphoto; private imageview fullimageview; private linearlayout llsetwallpaper, lldownloadwallpaper; private utils utils; private progressbar pbloader; private coordinatorlayout coordinatorlayout; private int progressstatus = 0; private handler handler = new handler(); private string licencseurl,licenseeurl = null; // picasa json response node keys private static final string tag_entry = "entry", tag_media_group = "media$group", tag_media_content = "media$content", tag_img_url = "url", tag_img_width = "width", tag_img_height = "height"; @override protected void oncreate(bundle savedinstancestate) { requestwindowfeature(window.feature_no_title); super.oncreate(savedinstancestate); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); setcontentview(r.layout.activity_fullscreen_image); fullimageview = (imageview) findviewbyid(r.id.imgfullscreen); llsetwallpaper = (linearlayout) findviewbyid(r.id.llsetwallpaper); lldownloadwallpaper = (linearlayout) findviewbyid(r.id.lldownloadwallpaper); pbloader = (progressbar) findviewbyid(r.id.pbloader); pbloader.setindeterminate(true); pbloader.setmax(100); getsupportactionbar().setdisplayhomeasupenabled(true); getsupportactionbar().sethomebuttonenabled(true); getsupportactionbar().settitle(""); coordinatorlayout = (coordinatorlayout) findviewbyid(r.id .coordinatorlayout); utils = new utils(getapplicationcontext()); // layout click listeners llsetwallpaper.setonclicklistener(this); lldownloadwallpaper.setonclicklistener(this); // setting layout buttons alpha/opacity llsetwallpaper.getbackground().setalpha(70); lldownloadwallpaper.getbackground().setalpha(70); intent = getintent(); selectedphoto = (wallpaper) i.getserializableextra(tag_sel_image); // check selected photo null if (selectedphoto != null) { // fetch photo full resolution image making json request fetchfullresolutionimage(); } else { toast.maketext(getapplicationcontext(), getstring(r.string.msg_unknown_error), toast.length_short) .show(); } } /** * fetching image fullresolution json * */ private void fetchfullresolutionimage() { string url = selectedphoto.getphotojson(); // show loader before making request pbloader.setvisibility(view.visible); llsetwallpaper.setvisibility(view.gone); lldownloadwallpaper.setvisibility(view.gone); getsupportactionbar().hide(); // volley's json obj request jsonobjectrequest jsonobjreq = new jsonobjectrequest(request.method.get, url, null, new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { log.d(tag, "image full resolution json: " + response.tostring()); try { // parsing json response jsonobject entry = response .getjsonobject(tag_entry); jsonarray mediacontentarry = entry.getjsonobject( tag_media_group).getjsonarray( tag_media_content); jsonobject mediaobj = (jsonobject) mediacontentarry .get(0); string fullresolutionurl = mediaobj .getstring(tag_img_url); // image full resolution widht , height final int width = mediaobj.getint(tag_img_width); final int height = mediaobj.getint(tag_img_height); log.d(tag, "full resolution image. url: " + fullresolutionurl + ", w: " + width + ", h: " + height); imageloader imageloader = appcontroller .getinstance().getimageloader(); // download image imageview instead of // networkimageview have callback methods // networkimageview doesn't have callback // methods /// progressstatus = 0; new thread(new runnable() { @override public void run() { while (progressstatus<100){ progressstatus += 1; handler.post(new runnable() { @override public void run() { pbloader.setprogress(progressstatus); } }); try { thread.sleep(100); }catch (interruptedexception e) { e.printstacktrace(); } } } }).start(); /// imageloader.get(fullresolutionurl, new imageloader.imagelistener() { @override public void onerrorresponse( volleyerror arg0) { toast.maketext( getapplicationcontext(), getstring(r.string.msg_wall_fetch_error), toast.length_long).show(); } @override public void onresponse( imageloader.imagecontainer response, boolean arg1) { if (response.getbitmap() != null) { // load bitmap imageview fullimageview .setimagebitmap(response .getbitmap()); adjustimageaspect(width, height); // hide loader , show set & // download buttons pbloader.setvisibility(view.gone); llsetwallpaper .setvisibility(view.visible); lldownloadwallpaper .setvisibility(view.visible); getsupportactionbar().show(); } } }); } catch (jsonexception e) { e.printstacktrace(); toast.maketext(getapplicationcontext(), getstring(r.string.msg_unknown_error), toast.length_long).show(); } } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { log.e(tag, "error: " + error.getmessage()); // unable fetch wallpapers // either google username wrong or // devices doesn't have internet connection toast.maketext(getapplicationcontext(), getstring(r.string.msg_wall_fetch_error), toast.length_long).show(); } }); // remove url cache appcontroller.getinstance().getrequestqueue().getcache().remove(url); // disable cache url, fetches updated // json jsonobjreq.setshouldcache(false); // adding request request queue appcontroller.getinstance().addtorequestqueue(jsonobjreq); } /** * adjusting image aspect ration scroll horizontally, image height * screen height, width calculated respected height * */ @suppresswarnings("deprecation") @suppresslint("newapi") private void adjustimageaspect(int bwidth, int bheight) { linearlayout.layoutparams params = new linearlayout.layoutparams( linearlayout.layoutparams.match_parent, linearlayout.layoutparams.match_parent); if (bwidth == 0 || bheight == 0) return; int sheight = 0; if (android.os.build.version.sdk_int >= 13) { display display = getwindowmanager().getdefaultdisplay(); point size = new point(); display.getsize(size); sheight = size.y; } else { display display = getwindowmanager().getdefaultdisplay(); sheight = display.getheight(); } int new_width = (int) math.floor((double) bwidth * (double) sheight / (double) bheight); params.width = new_width; params.height = sheight; log.d(tag, "fullscreen image new dimensions: w = " + new_width + ", h = " + sheight); fullimageview.setlayoutparams(params); } /** * view click listener * */ @override public void onclick(view v) { bitmap bitmap = ((bitmapdrawable) fullimageview.getdrawable()) .getbitmap(); switch (v.getid()) { // button download wallpaper tapped case r.id.lldownloadwallpaper: utils.saveimagetosdcard(bitmap, coordinatorlayout); break; // button set wallpaper tapped case r.id.llsetwallpaper: utils.setaswallpaper(bitmap, coordinatorlayout); break; default: break; } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_fullscreen, menu); return true; } private void gotourl(string url) { uri uri = uri.parse(url); intent gotowebsite = new intent(intent.action_view, uri); // count play market backstack, after pressing button, // taken our application, need add following flags intent. int flags = intent.flag_activity_no_history | intent.flag_activity_multiple_task; if (build.version.sdk_int >= 21) { flags |= intent.flag_activity_new_document; } else { //noinspection deprecation flags |= intent.flag_activity_clear_when_task_reset; } gotowebsite.addflags(flags); try { startactivity(gotowebsite); } catch (activitynotfoundexception e) { } } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); bitmap bitmap = ((bitmapdrawable) fullimageview.getdrawable()) .getbitmap(); switch (id) { case android.r.id.home: finish(); return true; case r.id.action_set_as_wallpaper: utils.setaswallpaper(bitmap, coordinatorlayout); return true; case r.id.action_download: utils.saveimagetosdcard(bitmap, coordinatorlayout); return true; case r.id.action_share: utils.shareimage(bitmap, coordinatorlayout); return true; case r.id.action_report: utils.reportimage(bitmap); return true; default: return super.onoptionsitemselected(item); } } }
maniactivity.java
package com.saveitornot.wallit; import android.app.fragment; import android.app.fragmentmanager; import android.app.fragmenttransaction; import android.content.intent; import android.os.bundle; import android.support.v4.widget.drawerlayout; import android.support.v7.app.appcompatactivity; import android.support.v7.widget.toolbar; import android.util.log; import android.view.menu; import android.view.menuitem; import android.view.view; import com.saveitornot.wallit.app.appcontroller; import com.saveitornot.wallit.picasa.model.category; import com.google.android.gms.ads.adrequest; import com.google.android.gms.ads.adview; import java.util.arraylist; import java.util.list; public class mainactivity extends appcompatactivity implements fragmentdrawer.fragmentdrawerlistener { private static final string tag = mainactivity.class.getsimplename(); private toolbar mtoolbar; private fragmentdrawer drawerfragment; private list<category> albumslist; private arraylist<navdraweritem> navdraweritems; string name = new string("main grid screen"); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); navdraweritems = new arraylist<navdraweritem>(); // getting albums shared preferences albumslist = appcontroller.getinstance().getprefmanger().getcategories(); // insert "recently added" in navigation drawer first position /* category recentalbum = new category(null, getstring(r.string.nav_drawer_recently_added), "(100)"); albumslist.add(0, recentalbum);*/ // loop through albums in add them navigation drawer adapter (category : albumslist) { navdraweritems.add(new navdraweritem(true, a.getid(), a.gettitle(), a.getphotono())); // titles a.gettitle() } mtoolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(mtoolbar); getsupportactionbar().setdisplayshowhomeenabled(true); drawerfragment = (fragmentdrawer) getsupportfragmentmanager().findfragmentbyid(r.id.fragment_navigation_drawer); drawerfragment.setup(r.id.fragment_navigation_drawer, (drawerlayout) findviewbyid(r.id.drawer_layout), mtoolbar); drawerfragment.setdrawerlistener(this); adview madview = (adview) findviewbyid(r.id.adview); adrequest adrequest = new adrequest.builder().build(); madview.loadad(adrequest); displayview(0); } private void displayview(int position) { // update main content replacing fragments fragment fragment = null; string albumid = ""; switch (position) { case 0: // added item selected // don't pass album id grid fragment /*log.e(tag, "gridfragment creating"); fragment = gridfragment.newinstance(null);*/ albumid = albumslist.get(position).getid(); fragment = gridfragment.newinstance(albumid); break; default: // selected wallpaper category // send album id grid fragment list wallpapers albumid = albumslist.get(position).getid(); fragment = gridfragment.newinstance(albumid); break; } if (fragment != null) { fragmentmanager fragmentmanager = getfragmentmanager(); fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction(); fragmenttransaction.replace(r.id.container_body, fragment); fragmenttransaction.commit(); // set toolbar title getsupportactionbar().settitle(albumslist.get(position).gettitle()); } else { // error in creating fragment log.e(tag, "error in creating fragment"); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { intent intent = new intent(mainactivity.this, settingsactivity.class); startactivity(intent); return true; } return super.onoptionsitemselected(item); } @override public void ondraweritemselected(view view, int position) { displayview(position); } }
here xml file
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.coordinatorlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/coordinatorlayout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".fullscreenviewactivity"> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/black" > <progressbar android:id="@+id/pbloader" style="?android:attr/progressbarstylehorizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerinparent="true" android:progresstint="@color/colorprimary" android:progressbackgroundtint="@color/white" android:minheight="50dp" android:minwidth="200dp" android:progress="1"> </progressbar> <!-- scroll view fullscreen preview --> <horizontalscrollview android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="none" > <linearlayout android:layout_width="wrap_content" android:layout_height="match_parent" android:weightsum="1"> <imageview android:id="@+id/imgfullscreen" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaletype="fitxy" /> </linearlayout> </horizontalscrollview> <!-- set wallpaper button --> <linearlayout android:id="@+id/llsetwallpaper" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_marginbottom="10dp" android:layout_marginleft="10dp" android:background="@drawable/btn_rounded_corner" android:gravity="center_vertical" android:orientation="horizontal" > <imageview android:layout_width="25dp" android:layout_height="25dp" android:src="@drawable/ico_apply" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingleft="10dp" android:text="@string/set_wallpaper" android:textcolor="@color/white" android:textsize="18dp" /> </linearlayout> <!-- download wallpaper button --> <linearlayout android:id="@+id/lldownloadwallpaper" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentright="true" android:layout_marginbottom="10dp" android:layout_marginright="10dp" android:background="@drawable/btn_rounded_corner" android:gravity="center_vertical" android:orientation="horizontal" > <imageview android:layout_width="25dp" android:layout_height="25dp" android:src="@drawable/ico_download" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingleft="10dp" android:text="@string/download_wallpaper" android:textcolor="@color/white" android:textsize="18sp" /> </linearlayout> <android.support.v7.widget.toolbar android:id="@+id/fragmenttoolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" android:minheight="?attr/actionbarsize" app:popuptheme="@style/themeoverlay.appcompat.light" app:theme="@style/themeoverlay.appcompat.dark.actionbar" /> </relativelayout> </android.support.design.widget.coordinatorlayout>
<horizontalscrollview android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="none" > <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:weightsum="1">
try change android:layout_width="wrap_content" android:layout_width="match_parent". help?
Comments
Post a Comment