Android layout issue with buttons below WebView - android

So I have a webview I'd like to display as a dialog. I'd like the webview to fill the entire screen, except for a button below it that I'd like to stay at the bottom of the dialog regardless of how much content is in the webview. Currently my webview fills up the dialog just enough to push the button off the screen. I'm sure this is something pretty easy but for the life of me, I haven't been able to find the magical combination of layouts, views and attribute values to get it to play nice. Just to be clear, I've gotten it so the button floats over the webview but I'd like the webview to stop just above the button and scroll, if that makes sense.
<RelativeLayout android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<WebView android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button android:text="Ok"
android:id="#+id/btnOk"
android:layout_width="120px"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>

You will want to use android:layout_above="#+id/btnOk" for your webview, and do fill_parent for width and height of the webview.
However, it is important to note, that in 1.5 and below, RelativeLayout views need to be specified in order in your xml to be recognized correctly.. in other words, you have to have your Button first, then the WebView, since the WebView will reference the button. I think this has been changed in 1.6 or 2.0, but I am not positive which.
<RelativeLayout android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button android:text="Ok"
android:id="#+id/btnOk"
android:layout_width="120px"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
<WebView android:id="#+id/webview"
android:layout_above="#+id/btnOk"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>

Related

android : when is webview ready to layout?

My activity consists of a WebView and a couple buttons. I'm trying to display the buttons at the bottom of the activity, but ensure that the user must scroll through the content if it is taller than the screen. As part of my solution I have set the WebView's layout_height attribute to wrap_content.
Problem is, even though I call WebView.loadData() from within onCreate(), the WebView does not size itself right away. In the case where the web content is taller than the screen, the buttons initially appear at the bottom of the activity, and then move off-screen when the web content appears. I want to prevent the buttons from appearing at all before the web content is sized, so that when they do appear they always appear in the right place. To this end I have tried using onPageFinished (it gets called too early) and onPictureListener (it is never called at all).
How can I determine when the WebView is ready for layout?
This is my XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.webkit.WebView
android:id="#+id/wv"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:id="#+id/btns"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:gravity="bottom" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClickButton1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClickButton2" />
</LinearLayout>
</LinearLayout>
</ScrollView>

put a button in frameLayaout

I have a small application with the camera and I have a device which is not a problem but if I can change the app will improve much aesthetically.
I put the xml code of the activity:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/layout">
<FrameLayout
android:id="#+id/preview"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="0dip">
</FrameLayout>
<Button
android:id="#+id/buttonClick"
android:layout_width="109dp"
android:layout_height="105dp"
android:layout_gravity="center"
android:background="#drawable/obutrador2" >
</Button>
</LinearLayout>
When I run the application, there is a white stripe along the entire height of the screen occupied by the button. How I can fix this? It would make the button appear above the image that the camera is capturing, as the app that has the default phone.
The problem is how to position the frame layout so that it fills the screen and center the button at the bottom. If I make the FrameLayout full-screen, the button disappears.
I leave a link to a photo of what happens:
https://www.dropbox.com/s/jbns8jddtwxjhdp/IMAG0348.jpg
I think you should define Button inside the FrameLayout like this.
You can make FrameLayout as parent layout and you can place button where ever you want
<FrameLayout
android:id="#+id/preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="#+id/buttonClick"
android:layout_width="109dp"
android:layout_height="105dp"
android:layout_gravity="center"
android:background="#drawable/obutrador2" >
</Button>
</FrameLayout>
Hope This should be work for you...Thanks

Android - How to enable full page scrolling on a layout with a ListView?

I have a layout with a ListView. The list scrolls fine, but sometimes the other content on the page needs to be bigger and either the list or the other content take up too much of the screen so I need it all to scroll.
Can that be done?
Here is the layout I have so far:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<include android:id="#+id/header"
layout="#layout/header"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
<TextView
android:id="#+id/view_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Business:"
/>
<TextView
android:id="#+id/business_privacy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Loading..."
/>
<TextView
android:id="#+id/think"
android:layout_width="fill_parent"
android:layout_marginTop ="5dp"
android:textColor="#color/light_best_blue"
android:paddingLeft="10px"
android:layout_height="wrap_content"
android:text="Fill out each section below"
/>
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textSize="20px"
>
</ListView>
</LinearLayout>
What would be the way to make it easy for the user to be able to see both the text and the list even if the text takes up the whole screen? Can I make the text scrollable? It is especially bad in horizontal view so I think there must be some ux patters to make it play nicely.
Thanks for the advice!
1- Put textview which has a larger text in header of the list view so it get scroll with list...
or
2- put the textview in other scroll view with fixed size like 1/3 of the screen.
You could either make the content wrap, or wrap the content up using a HorizontalScrollView. Android docs on it can be found here.

Problem with the display of custom listview (webview in my listview)

I am having an issue that make me crazy
I have a listview with WebView inside. So I created a custom listview.
The WebView forbid me to click so I created a webviewclicklistener.
My problem was that when I display some images, my webviews are "shaking" as if it wants to load the image a thousand times.
In fact I discovered that the height size of some elements change like every seconds, that give a feeling of shake.
The only way I found to fix it is to give a layout:height value for my listview.
My new problem is that when I put for exemple 600dip, I have a scrollbar, but I can't look at the end of my listviews.
If I put like 1000dip, I don't have scroll bar and I can't see the end of my list neither.
Here is my layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:background="#drawable/woodbackground"
android:layout_weight="1">
<TextView android:background="#android:color/transparent"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:hint="Question" android:textSize="30px"></TextView>
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical">
<WebView android:id="#+id/wvplquestion" android:layout_height="wrap_content"
android:layout_width="fill_parent"></WebView>
</ScrollView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#android:color/transparent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical"
android:layout_weight="1">
<TextView android:background="#android:color/transparent"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:hint="Select Answer" android:textSize="30px"></TextView>
<ListView android:id="#+id/lvquestion" android:layout_width="fill_parent"
android:layout_height="600dip" android:prompt="#string/selectp" />
</LinearLayout>
And my custom listview layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:padding="3dip">
<WebView android:id="#+id/weblistview" android:layout_width="fill_parent"
android:layout_height="wrap_content"></WebView>
Thanks for your help
maybe you can try to change your listview layout height. Instead of wrap content, put a fixed height. I don't know if it will be working, but you can try it. I'd a problem similar to yours and I solved it like this.
I hope it will work. Good luck ;)
Seems it mostly happens when several webviews contained into one scrollview. Seems at least first webviews should have fixed height.

Align AdView (AdMob) to bottom of screen with WebView on Android Layout

The default screen of my app shows a ListView. When the user selects an entry a new Activity is displayed with a Title (TextView), some information gained from xml (WebView).
I want to place an Ad aligned to the bottom of this second Activity.
My layout currently is this:
<LinearLayout android:id="#+id/info" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" style="#style/info">
<TextView android:id="#+id/title" style="#style/title" />
<WebView android:id="#+id/info" style="#style/info" />
</LinearLayout>
This works perfectly, but I can't get the Ad to always be at the bottom.
I've tried RelativeLayout, but no matter what, I always get the same results!
If the HTML shown in the WebView is short enough for the AdView to be displayed (but not at bottom, underneath WebView) or its too long and the AdView is not shown at all!
I want the AdView always visible always, even if the WebView scrolls!
Hope this makes sense!
Neil
PS: I'll continue to look for answers and update if I find one....
Figured out a way to solve this, but is it the best way??
This is how I did it:
<LinearLayout android:id="#+id/linearlayout" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:neildeadman="http://schemas.android.com/apk/res/com.neildeadman.android" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" style="#style/Info">
<LinearLayout android:id="#+id/info" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" style="#style/info">
<TextView android:id="#+id/title" style="#style/title" />
<WebView android:id="#+id/info" style="#style/info" />
</LinearLayout>
</LinearLayout>
The "layout_weight" attributes allowed me to force the inner LinearLayout to fill the remaining gap left by the add, which then contained my layout from above!
Works lovely....

Categories

Resources