Android - bottom bar overlapping SurfaceView -
ok, before i've asked question, i've looked at:
how remove unwanted overlapping in android
tabs @ bottom overlapping list view
android bottom navigation bar overlapping spinner. set spinner dropdown height / margin
bottom button bar overlaps last element of listview!
however haven't seen think fix particular situation. here's problem: i'm writing custom surfaceview display image on-screen. in surfaceview drawing image bottom right-hand corner. here code:
import android.annotation.suppresslint; import android.app.activity; import android.content.context; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.graphics.canvas; import android.graphics.point; import android.os.build; import android.os.bundle; import android.view.display; import android.view.surfaceholder; import android.view.surfaceview; import android.view.windowmanager; public class demosf extends activity { ourview v; int measuredwidth; int measuredheight; windowmanager w; bitmap whatever; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); measuredwidth = 0; measuredheight = 0; getscreenwidthandheight(); whatever = bitmapfactory.decoderesource(getresources(), r.raw.dragarrow); v = new ourview(this); setcontentview(v); } public class ourview extends surfaceview implements runnable { thread t = null; surfaceholder holder; boolean isitok; public ourview(context context) { super(context); holder = getholder(); } @override public void run() { while (isitok) { try { thread.sleep((long) 50); } catch (interruptedexception e) { e.printstacktrace(); } if (!holder.getsurface().isvalid()) { continue; } canvas c = holder.lockcanvas(); c.drawargb(255, 0, 0, 0); c.drawbitmap(whatever, ((float) measuredwidth - (float) whatever.getwidth()), ((float) measuredheight - (float) whatever.getheight()), null); holder.unlockcanvasandpost(c); } } public void pause() { isitok = false; while (true) { try { t.join(); } catch (interruptedexception e) { e.printstacktrace(); } break; } t = null; } public void resume() { isitok = true; t = new thread(this); t.start(); } } @override protected void onpause() { super.onpause(); v.pause(); } @override protected void onresume() { super.onresume(); v.resume(); } @suppresslint("newapi") @suppresswarnings("deprecation") public void getscreenwidthandheight() { point size = new point(); w = getwindowmanager(); if (build.version.sdk_int >= build.version_codes.honeycomb_mr2) { w.getdefaultdisplay().getsize(size); measuredwidth = size.x; measuredheight = size.y; } else { display d = w.getdefaultdisplay(); measuredwidth = d.getwidth(); measuredheight = d.getheight(); } } }
and thorough, here's manifest too:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.something" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" android:targetsdkversion="18" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.example.something.mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="com.example.something.demosf" android:label="@string/app_name" android:screenorientation="landscape" android:theme="@android:style/theme.notitlebar.fullscreen" > <intent-filter> <action android:name="com.example.something.demo" /> <category android:name="android.intent.category.default" /> </intent-filter> </activity> </application> </manifest>
now problem seem having, on nexus 7 works out i'd expect. on friends toshiba thrive, bottom of image cut off bar on bottom. here's comparison: nexus7 on right, thrive on left. question is: happening, , how can fix this? (preferably android versions) oh, side question: bottom bar called? lol
edit: i'm aware it's not best code, i'm using code demonstrate what's happening , perhaps find different approach "getscreenwidthandheight()" method accounts odd overlap in devices occurs in
instead of:
c.drawbitmap(whatever, ((float) measuredwidth - (float) whatever.getwidth()), ((float) measuredheight - (float) whatever.getheight()), null);
use:
c.drawbitmap(whatever, ((float) this.getwidth() - (float) whatever.getwidth()), ((float) this.getheight() - (float) whatever.getheight()), null);
reason:
your method of positioning bitmap assumes no screen decorations present @ bottom. in fact, not account decor views @ all. should handling positioning using dimensions of activity's view.
edit:
in activity's case, following view's dimensions:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); measuredwidth = 0; measuredheight = 0; getscreenwidthandheight(); whatever = bitmapfactory.decoderesource(getresources(), r.raw.dragarrow); v = new ourview(this); v.post(new runnable() { @override public void run() { measuredwidth = v.getwidth(); measuredheight = v.getheight(); } }); setcontentview(v); }
edit 2:
linearlayout llmain; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); measuredwidth = 0; measuredheight = 0; //getscreenwidthandheight(); whatever = bitmapfactory.decoderesource(getresources(), r.raw.dragarrow); llmain = new linearlayout(this); setcontentview(llmain); llmain.post(new runnable() { @override public void run() { measuredwidth = llmain.getwidth(); measuredheight = llmain.getheight(); scaleandtrimimages(); v = new ourview(demosf.this); llmain.addview(v); } }); } public void scaleandtrimimages() { // use measuredwidth , measuredheight // since calling method oncreate(bundle), // runs once. }
Comments
Post a Comment