I have a custom View that I would like to "embed" in an WebView.
By embed I mean:
The custom view intercepts onTouch events on its area
The custom view looks like a piece of the web page, so it scrolls with the surrounding text
I wrote the custom View, so I can edit it as needed
Take a RelativeLayout or FrameLayout as Parent. then Put WebView as First Child Layout and then your CustomView as second child view.
After this put some code to show and hide the CustomView on some specific Action.
It will surly help you.
Enjoy. :)
as I said in my comment.
I can't think of a normal way to what you do. What I would do if I were you is to put the custom view in between 2 WebView objects like this:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView android:id="#+id/webView1
...
/>
<include android:layout="custom_layout" />
<WebView android:id="#+id/webView2
...
/>
</ ScrollView>
Related
i have create a custom view class, this class contains three TextViews. I am just using this custom view in on of my Fragment layout. My layout is like below
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.abc.views.HeaderView
android:id="#+id/headerView"
android:visibility="visible"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</com.rfs.app.views.HeaderView>
<ScrollView
android:id="#+id/widget54"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/footerView"
android:layout_below="#+id/headerView" >
--------------------------------------
--------------------------------------
</ScrollView>
</RelativeLayout>
The problem is, HeaderView child's updating(change text/color) when i click on button in my fragment. these changes are not reflecting instantly.
all child's are textviews in HeaderView class.
Is there any way to re-fresh or re-create this custom view?
Obviously your custom view doesn't invalidates itself correctly. Please make sure you call invalidate or postInvalidate if doing work in background thread, whenever you want your custom view to call onDraw. You can share your custom view code so that we can point out the issue here.
I'm struggeling to put a self-made view (size 3000px * 750 px) into any scrollView programmatically.
Information to my custom view: It simply extends View and there are just some drawing in OnDraw(), nothing special.
In order to gather all information for the drawing, this CustomView should be added, once a AsyncTask has loaded all information.
My problem is, that when I added my view programmatically to any ViewGroup containing a ScrollView or HorizontalScrollview, there is no Scrolling.
I've tried several layouts, for example this one:
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_marginTop="50dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="#+id/linLayoutScroll">
</LinearLayout>
</HorizontalScrollView>
And once the AsynTask is finished:
LinearLayout linLayout = (LinearLayout)rootView.findViewById(R.id.linLayoutScroll);
linLayout.addView(new MyChartView(getActivity(), chartBuilder, ChartBuilder.DATASET.SPEED));*/
I tried to add my view to the LinearLayout, but often my View does not appear on screen at all or there is no scroling option and my view gets cut off at the end of display.
I guess there must be some magic trick to tell the scrollView to recheck its content and to decide whether there has to be a scrolling option or not. Can anyone help me out?
The error was inside my customView. I didn't set the Width and Height of my view (setWidth(), setHeight()). So the view did not know how big it really is. :-(
Sorry for wasting your time!
My question is simple: How to disable any event on a View in Android? (including removing its focussability, like I just want it to be there visually but be inexistant on everything else)
And does it work on a whole view tree? (like if I disable events on the root, all the events will be disabled for its children?).
Now, before you say anything I have tried all the following:
setEnabled
setFocusable
setSelected
setClickable
setActivated
And none of these methods appear to work, seriously.
I have tried them directly on a WebView, as well as on the parent layout on everything but I am still able to interact with it.
Any idea?
Thanks!
EDIT#1
The solution that consists in adding a view on top of the view that needs to be disabled doesn't work. Actually, it's still possible to click on the inner view, I have tried with a simple example:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ff0000">
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Click Me!"
/>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
/>
</FrameLayout>
Here it's still possible to click on the button.
EDIT#2
The reason why I want to do this is related to the following question that I asked weeks ago.
What I have is a ListViewacting as a navigation bar which is underneath a View that holds the content of my app. The problem with this implementation is that when I try to scroll through the ListView when there is a focusable view in the layer on top of it, well the ListView doesn't scroll and instead it's the top view that takes focus (That's the case when there is a
Webview or an EditText etc.).
So yes as mentioned in one of the answers, I can disable any click events on a WebView by overriding setOnTouchListener but the view remains focussed and I think this is the reason why I am still having the same issue with my navigation bar.
Simply put a view on top of your view. You can toggle it on off by setting view.visibility = gone/visible.
<FrameLayout>
<WebView/>
<FrameLayout This view will be on top/>
</FrameLayout>
Edit: Just stumpled upon this link: https://stackoverflow.com/a/3856199/969325
Basically disables all touch event for the webview. Tryed that?
Edit 2 reedit: Try to set the visibility to gone for the the top view below your listview.
i have set up an activity that loads up the camera and allows me to preview it but i need to add a button to the screen but the only way i can get the screen to display is by using the following layout:
<android.view.SurfaceView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.view.SurfaceView>
is there a way for me to add a button to the view?
Put your SurfaceView and button into a RelativeLayout. Both of those types of layouts allow views to overlap so your button will be on top of your SurfaceView. The set up would be something like this
<RelativeLayout>
<SurfaceView></SurfaceView>
<Button></Button>
</RelativeLayout>
DeeV's answer is correct for the RelativeLayout part. The FrameLayout isn't intented to contain multiple children. So the RelativeLayout is the way to go.
I'm populating an activity with a ListView that sometimes exceeds the window size vertically. Instead of the user being able to scroll the ListView, I want the ListView to just take up the space it needs and let the users scroll in the activity instead. Is this possible?
Here is an image for clarification: http://imgur.com/1I2bc
On both sides there is a ListView containing 8 elements, only the right one takes up the space it needs to show the list fully though, pushing the other views down and making the entire activity scrollable.
You need to use the methods addHeaderView and addFooterView to add views before and after the ListView.
To add several views, first put the views in a Layout or ViewGroup and add that ViewGroup as the header or footer view (ViewGroup is a subclass of View).
-have you tried to put your scroll element as top level element in your layout .xml?
Something like this:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView
android:id="#+id/listView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
</ListView>
</ScrollView>