Invisible RelativeLayout with a SurfaceView - android

I am trying to develop a face recognition application and I am using a SurfaceView inside a RelativeLayout. I was able to make the SurfaceView "TRANSPARENT" so I did not need to see the Camera preview, but now I am having a white background caused by the RelativeLayout and I can't make it Invisible so I don't see this background in my application.
I tried many things and i looked a lot of posts here in SO but I didn't find a solution for my situation.
Xml code (margins in relativelayout and surfaceview were for testing purposes):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/topLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:visibility="invisible">
<SurfaceView
android:id="#+id/surfaceview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="100dp"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="#dimen/image_preview"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
android:scrollbars="vertical" />

instead of making it invisible remove it altogether by adding this to the layout:
android:visibility="gone"
and then set it to visible programmatically when you need it again.

Related

Android: Cover underlying elevated views, and making a flat button

Sorry for the elementary question but I can't find the solution:
When covering a button with a layout without elevation, it emerges over the layout because a button has a depth (negative depth, it points at the viewer).
So, if you have a
<FrameLayout... >
<Button.../>
<FrameLayout
id="#+id/fragmentsContainerOrAnything"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C00F"
android:clickable="true"
android:focusable="true"
>
</FrameLayout>
</FrameLayout>
The button would show through the FrameLayout.... In this case, literally "out of the blue" because the button has depth and so it emerges over the layout, even though the layout is placed "upon" the button.
The question is:
How do I make the FrameLayout cover the underlying Button without fiddling with its elevation.
How do I make the button flat? Of course I can just set it back to the origins and call it "TextView". But is there a nicer way?
Thanks
Add your button inside FrameLayout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C00F"
android:clickable="true"
android:focusable="true" />
</FrameLayout>

Draw outside ScrollView

I'm using TwoDScrollView, but for sake of simplicity let's say I have a very simple layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootLayout"
android:background="#android:color/transparent"
android:clickable="true"
android:paddingTop="?attr/actionBarSize"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" >
<View
android:id="#+id/topOverview"
android:background="#cc000000"
android:layout_above="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ScrollView
android:id="#+id/scrollView"
android:fillViewport="true"
android:layout_centerVertical="true"
android:clipChildren="false"
android:layout_width="match_parent"
android:layout_height="100dp">
<ImageView
android:adjustViewBounds="true"
android:src="#drawable/my_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
<View
android:id="#+id/bottomOverview"
android:background="#cc000000"
android:layout_below="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
So I have a scrollView with ImageView inside (which is bigger ofc). Now I want to also draw what's outside scrollview. I also want to cover this area with 80% alpha-black views (using layout_above and layout_below) as you can see in xml. Thanks to that user will be able see area outside scrollview, but it will look different outside. I've tried clipChildren, but I doesn't work. It's still clipped anyway.
I've achieved this very easily on iOS by just one line of code (plus view above and below scrollView with correct constraints):
scrollView.clipsToBounds = false
It looks like that:
So how can I achieve it on Android? Canvas is too much for this I think. I've also came up with an idea that I can duplicate ImageView outside ScrollView, place it below it and move it as scroll moves. But is there an easier method?

How to add a view, above the webview, which will scroll together with it?

Im trying to add a a View above a webview that should scroll together with it.
Ive tried putting both views inside a scrollview like this:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#android:color/black" />
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
It worked pretty well until Ive encountered a problem in the case that the webview changes it size after it first renders (i.e. if the loaded url uses lazy loading on some of its components).
BTW it doesn't matter if the height or width of either the scroll\Linear\Web views is set to "match_parent" or "wrap_content" I still get the same problem.
Ive also tried using the "hidden" setEmbeddedTitleBar(View v) method that was introduced and then removed from the Android's WebView, in order to simply add a view above the WebView without the need of a wrapping scroll view.
I tried some hacks that were suggested here but I didn't find something that works.
Is there anyone who encunterd this problem and had find a successful way of achieving this?
Thanks a lot!
Try adding some weights to the layout like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="0"
android:background="#android:color/black" />
<WebView
android:id="#+id/webview"
android:layout_weight="1"
android:background="#color/brand_color"
android:layout_width="match_parent"
android:layout_height="0dp" />
</LinearLayout>

Android screen rendered really wrong

I'm using a GLSurfaceView to render a live wallpaper behind my apps interface which consists of android UI elements.
In the beginning of my app I ask the user if they would like to see this wallpaper or not.
ONLY if the user accepts the GLSurfaceView is inflated in the existing xml as a first element so it will stay behind.
My problem is exactly the opposite of what i would think it would.
When the wallpaper is ACTIVATED the screen renders properly, like so:
When I don't use the wallpaper it's rendered like a, partially burned graphic card:
As you see from the xml structure, my GLSurfaceView is not even injected in the problematic case.
Something weird is that when it's injected the DDMS Monitor displays it as just
If the opposite was the case it would be clear that the problem is caused by the GLSurfaceView. But now it seems as if the lack of it causes this problem.
Any ideas on what could be the problem?
I'm using Nexus 4 to test and it seems that it could be related based on DanJAB
XML layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
style="?metaButtonBarButtonStyle"
android:id="#+id/home_history"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/button_calibrator"
android:text="#string/history"/>
<View
android:id="#+id/button_calibrator"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/home_history"
android:layout_alignBottom="#+id/home_history"
android:layout_centerHorizontal="true"/>
<Button
style="?metaButtonBarButtonStyle"
android:id="#+id/home_help"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/button_calibrator"
android:text="#string/help"/>
<View
android:id="#+id/screen_menu_seperator"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="#+id/home_history"
android:background="#color/holo_blue"/>
<ListView
android:id="#+id/homescreen_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/screen_menu_seperator"
android:background="#android:color/transparent"
android:cacheColorHint="#android:color/transparent"/>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentBottom="true"
android:background="#color/holo_blue"/>
</RelativeLayout>
GLSurfaceView XML:
<?xml version="1.0" encoding="utf-8"?>
<android.opengl.GLSurfaceView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:visibility="gone"/>
and in java:
getLayoutInflater().inflate(R.layout.background, contents);
GLSurfaceView background = (GLSurfaceView) contents.findViewById(R.id.background);
This is a phone bug. Nexus 4 causes this issue with certain theme configurations.

Pass keyboard event to gridview?

I have a custom layout for the google tv and to get the layout to work, I override the dispatchkeyEvent in my activity to get my layout to work with the dpad. My layout also uses the gridview, and since I override the dispatchKeyEvent, I cant use the dpad with the gridview. Is there anyway to pass the key event to the gridview so I can use it?
Edit1: Apparently, the gridview cannot be focusd according to .isFocusable(). Is there anyway to force it to become focusable?
Edit2: I think the problem is the VideoView that is taking focus from all the controls?
Heres the layout I'm using. If I take out the VideoView, i am able to use the controls. The UI and Workspace layouts is my UI overlay over the video. Is there anway to get around this?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1" >
<VideoView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:id="#+id/ui"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom" >
<LinearLayout
android:id="#+id/workspace"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom" >
</LinearLayout>
</RelativeLayout>
</FrameLayout>

Categories

Resources