How to avoid mixup / clipping of tab layouts (incl. SurfaceView) in TabHost? - android

In my project I am using a tab host. In one of the tabs there is a Fragment Activity with a Fragment that includes an ImageView with some transparent regions as a background.
Now, in another tab I am incl. the (modified) CaptureActivity of the ZXing QR-Scanner library. I already went through all the hustle of making it work in portrait mode. My issue is, that when I open that one fragment mentioned above (and only in that specific case and order) before the CaptureActivity, the CaptureActivity's layout gets screwed up. The background image of the fragment is shown (although not incl. in this layout) and the camera preview is only shown in the transparent areas, see below.
Now, I don't know if that has to do with the surface view included here.
Somehow it seems to not only be a drawing / clipping issue, because the textview you can see is drawn on top of the surfaceview and is actually orientated android:layout_gravity="bottom|center_horizontal" (and works that way in every other case), but when this issue occurs the textview seems to be getting aligned within the other fragment layout that incl. the partially transparent background imageview.
Any hints are really appreciated. I can post some code if I have a lead what might be the problem here.
Thanks!

In the end I could solve the issue by renaming the drawable-png used as a drawable of the background imageview. Although I checked this before, I don't know if there was a mixup in the ids with the library or maybe I hit some kind of bug.

Related

Activities overlapping

I am new to writing Android apps, I have been using the internet and Android Studio to create an app for my club as a bit of fun and learn along the way. I have been watching videos, using tutorials and walkthroughs and I am getting to learn the basics.
However, I have got stuck. I used a drawer template from Android Studio and added the activities I needed and buttons on the main screen to the activities and they all worked fine, no overlapping. When I tried to link the drawer icons to the activities, rather than use the buttons on the main screen, they work, but the app (visually) puts the next activities content on top of the one before.
I cant find anything on the internet except something called backstacking, but that is described when the back arrow is used, my problem is to do with selecting an activity from the drawer menu. I have attached a picture to show what I mean. It gets worse the more menu items that are selected.
If anyone could help, it would be great!
If you are using XML root layout as a constraint layout maybe your constraints are missing. If you are using constraint layout set both top/bottom and left/right constraint.
If your constraints only top for example it is look good on desing but in device that dont know where to positioning left or right and automatically positioning 0 point to top.
When you click one any one menu item put the visibility of other images as gone like
visibility(View.GONE);
and the one selected to be visible

Android - Display a Map as a frame ontop of another activity

I have been trying to find a way to get this done but keep running into issues.
I want to be able to have a map in a frame (it does not necessarily have to be a FrameLayout, i just want it framed so it only takes up 1/2 or 2/3 the screen) ontop of my current layout and to have the current activity still displayed behind it.
In a perfect world, i would like to attach this view to a button and animation so clicking the button causes this view to slide in from offscreen left and settle in the center of my current activity, while still being fully clickable and and the map being useable (can zoom, click, etc.)
I have tried doing this with a fragment, but the issue is that the Activity i am working in is already extending another class that is absolutely necessary, so i can not extend Fragment or FragmentActivity, so i cant use fragments (unless i am missing a work around to achieve this.)
The same goes for MapActivity and MapView, cant extend the MapActivity class so cant use MapView.
Any time i try to inflate a map view or anything i get runtime errors because my activity does not extend the pertinent class. Is there a work around for this?
Does anyone have a suggestion as to how i can get this map to display the way i am looking for?
This is easily achieved in iOS but i cant seem to figure it out in Android.
Thank you in advance
EDIT
I am not looking for code, unless you have a specific example in which case obviously code is very helpful, but i am looking for an idea as to how to achieve this -- a push in the right direction if you will -- so i can write the code myself.
Solved this by adding a frame layout to my "Main" activity. That frame layout's class was set to my Map class. The Map class extended FragmentActivity and its contentView is set to my map_fragment.xml. The map_fragment.xml contains only a fragment and that fragments name is set to com.google.android.....SupportMapFragment.
After setting up my project in this way as well as setting up the correct screen layouts and dimensions for sizing purposes as well as defining a GoogleMap in my Map class, i was able to display a fully usable and interactive map over my "Main" activity.
I overrode some Activity transition animations to the Map class and got my project working 100% how i want it to.
I didnt ask for code, so i will not supply any code, but this process is pretty straight-forward if you follow the same process as i have described above.

Android xml:onclick from a layout with a glsurfaceview causes image drawables on previous activity to render as black

This is an odd problem that took me quite awhile to reproduce reliably.
I have a menu activity that is very simple; just some buttons defined in xml.
I have an activity with a layout with a GLSurfaceView and some buttons defined in xml.
These buttons have onClick attributes defined. This activity is accessed from the menu activity.
In the OpenGL activity there are the associated onClick functions "onFoo(View view)".
When I navigate back to the menu activity using the native Back button nothing interesting happens; however, when I click ANY of the xml defined buttons with an onClick attribute and then navigate back some of the ImageViews on the menu activity appear as black but otherwise in their correct locations, sizes, etc. Their xml defined onClick functions work correctly as well.
I am having all of the images on the menu activity re-exported (to eliminate any export setting flaws since the assets were originally exported at various times), but while I wait for that to happen I figured maybe someone out there has run into this problem before.
For the purpose of limiting variables in this problem I even commented out the function's contents in the OpenGL activity to make sure nothing in the onClick functions was causing a conflict.
e.g.
public void onMainMenu (View view)
{
}
So, to clarify, if I click a button defined in xml with an onClick attribute e.g.
android:onClick="onMainMenu" with the above empty method, then press the native back button the issue occurs, but not when skipping the clicking of the onMainMenu button.
I can't be sure if it is always the same set of ImageViews that turn black, but one ImageView does seem to consistently survive with the correct Drawable; this is odd because the ImageViews are defined identically other than their src attribute. They are all relatively the same size and not large at all.
I originally thought it had something to do with the EGL context (Android displays black rectangles instead of drawable images after opening openGL context) (and it still may be the case), but then I discovered how to reproduce it 100% of the time by pressing a button with an onClick attribute before navigating backwards. Memory usage is in control and I am lost for a possible solution or trail to one.
I can reproduce this on the three devices I have: an HTC One, Droid Bionic, Galaxy Tab 2 7.
The Application is minSdk:14, target:17. Hardware acceleration is on.
I tried playing with hardware acceleration settings with the following results:
If I turn off hardware acceleration for the application, and add it to just the OpenGl activity the main menu issue does not appear, but the same issue starts occurring in the OpenGL activity. In the case of this activity some ImageView's drawable resources are switched out at run-time. The switched in resources display correctly, but when switched back to the same resource that the was defined for that ImageView in xml it renders black.
To clarify the switching: in one such case I have views with a drawable-state-selector for their backgrounds. When switching between the two states (they function like tabs i.e. their default states as defined in xml are opposite) the default state always displays as black but the secondary state displays correctly.
If I turn off hardware acceleration for the application AND the OpenGL activity, the problem appears to go away completely.
I worry about using that as a solution though as I can't be sure of any performance problems that may occur on devices I do not have to test with.
Removing hardware acceleration from the OpenGL activity breaks a view that overlays the GLSurfaceView on at least the Droid Bionic, so I'd rather not use this pseudo-solution.
This is the first time I have posted a question on Stack Overflow. I always find a solid lead searching, but just could not find a solution or even a problem with similar circumstances in this case.
Thanks for any help and wisdom the community can provide!
The problem came down to a call to GLES20.glDeleteTextures(int size, int[] textureNames, int offset). I was calling this during onPause() which was somehow causing a conflict. I am not sure how it was related to touching a UI item outside of the GLSurfaceView. Removing the one call somehow prevents the issue.

Fragment animation question

In the Honeycomb sample gallery app, there's a layout that uses a two-fragment setup: one on the left of the screen showing titles, and one on the right showing the selected content. The titles fragment can be hidden with an animation.
During the hiding animation, the app asks the framework to recalculate the layout on every single frame. This way the content-fragment can take up the empty space that the titles-fragment leaves behind while it moves off-screen. This produces a great, dynamic effect, but is terribly inefficient I think.
I have fairly complex layouts, and I'd rather not ask the system to re-layout on every single frame. But I'd like a smooth transition animation like in the sample. Are there any alternative solutions to this problem?
P.s.: Just to be clear, I'm not asking how to do basic fragment-transaction animations. I know those, and AFAIK, those animations can't produce the behaviour found in that sample gallery app (another example would be the Honeycomb Gmail app, it has similar transitions that I'd like to achieve).
You can provide custom animations to the fragment system that do whatever you want. You can move the fragments around, fade them, etc. If these animations do not explicitly or implicitly cause layout (by changing properties that trigger a layout), then you should not get a layout on each animation frame. There maybe still be a layout call at the beginning/end as the fragments are added/removed, but the layout/invalidation process during the animation is up to your animations and what they do.

Positioning elements outside an Activity on Android

Is there a way to absolutely position an UI element on Android so that it is located outside an Activity? For example: can you create a fullscreen ImageView simply by moving/resizing an ImageView inside an existing regular Activity instead of creating a new fullscreen activity?
EDIT: Re-reading my question I see I wasn't very clear about what I'm trying to accomplish. I'd like to temporarily extend an element to cover the notification bar at the top of the screen. I need to create a semitranslucent fullscreen overlay but since translucent activities cannot cover the notification bar I'm trying to find out if it's possible for an element to break out of activity's bounds and resize itself to fill the whole screen, top to bottom.
That depends on what specifically you're trying to do. You can easily draw graphics offscreen and then animate their movement into the screen using a Canvas, but this is more for graphics than for user-interface elements. For moving buttons or such, you can have a look at another question here "How to position View off-screen". I gave a brief intro on how to use canvases, but the questioner found another way to do it using a customised linear layout and view animations.
Lastly, if you're trying to zoom and scroll an image around that's larger than the ImageView, there are some sources you can look at for inspiration. I realies this isn't strictly your question, but I'm including it since it might be linked to what you're thinking about. You can find a tutorial on Anddev.org and an open source app on Google Code.

Categories

Resources