i want similar map behavior have large image (bigger phone screen) , group of buttons want put on special xy locations on image, , when user scrolls image (horizontally , vertically), buttons keep same position on image (like markers do). user can click on button , open new activity.
i want in xml. suggestion?
i cant figure out how attach buttons image xy positions:
<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/map_view" android:background="@drawable/myimage"/> <radiobutton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="position 1" android:id="@+id/radiobutton" /> <radiobutton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="position 2" android:id="@+id/radiobutton2" /> <radiobutton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="position 3" android:id="@+id/radiobutton3" />` /> </relativelayout> </scrollview>
thanks @sheychan gave me clue getting wanted.
first of all: xml. use 2 scroll views (one main vertical, , horizontal), can horizontal , vertical scrolling. relativelayout can put radiobuttons on image in desired positions. important "src" , "scaletype" in image can correct image dimensions. here code xml
<scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/svvertical"> <horizontalscrollview android:id="@+id/hsvhorizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:isscrollcontainer="true"> <imageview android:id="@+id/map_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/imagen" android:scaletype="centercrop"/> <radiobutton android:id="@+id/radiobutton" android:layout_margintop="20dp" android:layout_marginleft="50dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="position 1"/> <radiobutton android:id="@+id/radiobutton2" android:layout_margintop="200dp" android:layout_marginleft="50dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="position 2"/> <radiobutton android:id="@+id/radiobutton3" android:layout_margintop="80dp" android:layout_marginleft="60dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="position 3"/> </relativelayout> </horizontalscrollview> </scrollview> but solution got odd scrolling (only vertical or horizontal, not both @ same time: call "diagonal" scrolling). resolve this: simple override on activity holding layout:
scrollview scrolly; horizontalscrollview scrollychild; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); scrolly = (scrollview)findviewbyid(r.id.svvertical); scrollychild = (horizontalscrollview)findviewbyid(r.id.hsvhorizontal); } @override public boolean dispatchtouchevent(motionevent event) { scrollychild.dispatchtouchevent(event); scrolly.ontouchevent(event); return super.dispatchtouchevent(event); } this start working better, still in odd way. move "jumps" while scrolling.
the solution: take away action bar:
on manifest, add "noactionbar" theme in application tag (or activity tag)
<application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@android:style/theme.holo.noactionbar.fullscreen" > ... </application> but, careful, cause activity must not "actionbaractivity", must change "activity".
and, in case, android recommendation, add compatible old sdk versions "hide status bar" on oncreate of activity.
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // if android version lower jellybean, use call hide // status bar. if (build.version.sdk_int < 16) { getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); } setcontentview(r.layout.activity_main); scrolly = (scrollview)findviewbyid(r.id.svvertical); scrollychild = (horizontalscrollview)findviewbyid(r.id.hsvhorizontal); } and that's folks :) hope helps helped me.
Comments
Post a Comment