Is there a way to get a Map or MapView without placing a MapFragmet inside a Layout?
<com.here.android.mpa.mapping.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/here_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
I already tried to place a MapView directly in my layout but there is no method to initialize or request a Map from it.
You can have a com.here.android.mpa.mapping.MapView in your layout without the use of a fragment.
Simply call new com.here.android.mpa.mapping.Map() and call com.here.android.mpa.mapping.MapView#setMap( map ) to attach the map to the map view.
Note you can only attach each map to a single map view. Also, make sure to call Mapview#onPause() and MapView#onResume() or the underlying textureview will not work correctly!
References:
https://developer.here.com/documentation/android-premium/api_reference_java/com/here/android/mpa/mapping/MapView.html#setMap-com.here.android.mpa.mapping.Map-
Related
I have a fragment with constraints that I want to preserve
<fragment
android:id="#+id/fr_test"
android:name="com.test.FragmentTest"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
I use transactions to hide/show it and all . works fine
fm.beginTransaction().hide(mainActivity.fr_test).commit()
fm.beginTransaction().show(mainActivity.fr_test).commit()
I use transactions to recreate fragment keeping the same container to use the same constraints
fm.beginTransaction().replace(R.id.mainActivity.fr_test, FragmentTest).commit()
But if now I try to hide/show the fragment with the same references as before it does nothing. I suppose that references are lost but I don't know how to find them. I tried to save the reference like this:
fragRef = FragmentTest()
viewsManager.fm.beginTransaction().replace(R.id.fr_test, fragRef).commit()
and then use:
fm.beginTransaction().hide(mainActivity.fragRef).commit()
fm.beginTransaction().show(mainActivity.fragRef).commit()
but still does the same.
What I'm doing wrong?
When you call replace, he calling remove(fragment) and after call add(int, fragment, string). I think that you should use add method instead replace and control your UI using hide and show
I want an application that uses Samsung S Pen as input, and draws something with OpenGL ES.
Basicly i need two views (both inherited from android.view.SurfaceView)
GLSurfaceView
SpenSurfaceView
The SpenSurfaceView should be on top, to catch all the input gesture.
The GLSurfaceView must be visible too. I might need to change visibility of the SpenSurfaceView (probably with the .setAlpha(float) method )
What is the most common way to implement this?
<FrameLayout>
<GlSurfaceView ... />
<SpenSurfaceView ... />
</FrameLayout>
or, if you can't use resources and the layout inflater:
FrameLayout fl = // get or find frame layout
fl.addChild(yourGlSurfaceView);
fl.addChild(yourSpenSurfaceView);
The greater question is, can you not just draw to the SpenSurfaceView's surface directly? Then you don't need the second GlSurfaceView.
I need to implement an interactive graph in Android
For a start I am trying to see how this code works
There, in a class called LineChartView Which extends the user generated class ChartView which extends the View class, there is an #overrideed function called onDraw(Canvas canvas). How and when does this function get called? the output of that code is a bunch of graphs on full screen, but my interactive graph should only take up a part of the screen. Does the onDraw() function get called automatically? If so, when? And what is the size of the canvas? Is it always the full screen occupied by the current activity's window?
in this link View Android Developer there is a section on implementing a custom view
onDraw(Canvas canvas) is called whenever a view should render its content
if you define to use this view in your layout xml or even in code you can specify the attributes
android:layout_width=
android:layout_height=
and those attributes will be applied to the size that the view will use
in your layout.xml
<your.package.name.extendedviewclass
android:layout_width="100dp"
android:layout_height="100dp"/>
Can anyone explain how can I add shape (for example a rectangle or an arrow) on to a image (in ImageView)? Once added, the shape will need to be draggable to anywhere in the image. And finally need to save the image edited (with the shape on top of that).
What informations do you really need?
This can be some steps to do:
Maybe create a new object to handle this:
Create a new class and extend from ImageView or use LayerDrawable for that.
Write setters/getters for the main-background-image/bitmap.
Add your own Vector shape (create a new class with definable color,thickness... or hard-code it)
Do all of your drawings in onDraw-Methods
Implement onTouch interfaces to handle your selection and dragging.
Create new method (render to jpeg/png/..) to save your resulting image
Create a Custom view from View that completely overlaps your ImageView. This view will have a transparent background and contain the draggging view. Initially set visibility to invisible.
In Custom view class override the onTouch event where you update the dragging views margins.
On save, get drawing cache of the parent layout(that contains both the ImageView and Custom view) and use as needed.
Sample xml code:
Relative layout parent whose drawing cache has to be grabbed using rel.getDrawingCache()
<RelativeLayout .......>
<ImageView ......./>
<CustomView ......./>
</RelativeLayout>
Suppose I have 2 XML files and my activity will setContentView the appropriate one based on some button press from the user. Is it possible to change the transition animation for the changing of content view?
So far I see super.overridePendingTransition() which is suitable for starting new activities, however my example does not start a new activity, it just changes the layout in the current one.
Mathias Lin has explained it very well.
You can always use default stock animations supplied by Android framework.
Heres an example code:
boolean isFirstXml=evaluatingConditionFunction();
LayoutInflater inflator=getLayoutInflater();
View view=inflator.inflate(isFirstXml?R.layout.myfirstxml:R.layout.myseconxml, null, false);
view.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right));
setContentView(view);
Call this from any of your activity which holds your Parent View.
For custom animations you can visit developer docs. Heres the documentation link.
Yes, you can apply an animation on almost any view you like. Just via view.startAnimation(animation);
Take the outer viewgroup of your respective layout (content view) and apply the animation to it. Depending what kind of animation you want to do, it might make sense to inflate/load both layouts but hide one of them and then swap. Please specify what kind of transition you have in mind.
For example: if you do an alpha transition, you would run the alphaAnimation on the current layout, when when the animation ends (AnimationListener), you set the content view to the new layout, and fade the content back in, via another alphaAnimation.
A better solution is using ViewFlipper: it is a FrameLayout, that can do animations when changing the views.
<ViewFlipper
android:id="#+id/[your_id_here]"
android:inAnimation="..."
android:outAnimation="..."
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
<!--Your first layout -->
</RelativeLayout>
<RelativeLayout
<!--Your second layout -->
</RelativeLayout>
</ViewFlipper>
Then, switch the views with setDisplayedChild(int) or showNext() or showPrevious. If you want to have different animation for left and right movement, you have to set inAnimation and outAnimation in the code before transition.
More complete example is here.