Android Webview with child at bottom - android

I've been searching both Google and stackoverflow for a while now and haven't found anything answering my question.
I'm wondering about putting a LinearLayout (with no specific known height in pixels) at the bottom of a WebView. This LinearLayout will later be populated with a fragment containing comments for the article displayed in the WebView.
The issue of the problem is that the WebView is almost always larger than the screen so the user has to scroll to read the full article. At the bottom of the scrolling I want the CommentsFragment to be inserted (through the LinearLayout, it takes a few parameters so it can't be loaded directly from the XML).
I've tried a bunch of solutions but all of them make the LinearLayout stick to the bottom of the layout the all time, not on the bottom of the WebView.
My current code is the following, of course not working:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="#+id/article_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true" />
<LinearLayout
android:id="#+id/comments_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Thank you for your help!

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="#+id/article_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/comments_container"
android:layout_below="#+id/article_webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>

got it working after a few rounds. The solution was using a ScrollView then inside that a relativelayout mirroring #Karan_rana's answer.

If you want to put the comments fragment below web view then you can try as following and tell me if it works for you
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="#+id/article_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/comments_container"/>
<LinearLayout
android:id="#+id/comments_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>

Try this, make sure to have layout_height="wrap_content" in your WebView
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<WebView
android:id="#+id/article_webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:id="#+id/comments_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>

Related

Vertical and horizantal Scrollview

I'm trying to build Scrollview that scrolls horizontally and vertically
i tried the below code but its not working
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="#+id/ScrollView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<HorizontalScrollView android:id="#+id/HorizontalScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
/// whatever goes here
</HorizontalScrollView>
</ScrollView>
from this post and tried this post too, is there any open source to this kind of View? Any help would be greatly appreciated.
Try this code snippet.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:scrollbars="vertical">
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="320px" android:layout_height="fill_parent">
<!-- put your subviews here -->
</HorizontalScrollView>

How to show other views after list view height set to fill_parent

To prevent multiple GetView calling I have set the height of ListView to fill_parent.
How to show other views than the ListView itself?
The following layout is inflated in a ViewPager:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="15dp" >
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>
where the included layout is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="20dp" >
<ScrollView
android:id="#+id/prontuariohome_scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none" >
.
.
.
.
</ScrollView>
</LinearLayout>
EDIT: This solution won't work for view higher than a button
I don't understand what you want to achieve, but if you NEED to have the height as fill_parent for some reason and can't be any other value, you can put the ListView with inside a LinearLayout with the height="0dp" and weight="1". So would be something like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="15dp" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>
Try to use following code
android:layout_height="0dp"
android:layout_weight="1"
in ListView tag
With android:layout_height="0dip" the view will take the rest of the free place
You said this solution is wont work:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/lv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white" android:layout_above="#+id/bt"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bt" android:layout_alignParentBottom="true"/>
just add it a android:layout_above="#+id/bt" to listview.
I'm sorry for being not clear.
Here is the link of the (probably) main thread asked here in Sof about the issue I was talking about.
After some tries I'm happy to give you the solution of my problem.
Giving another layout above the ListView lets the LV cuts the space not filled by the ListView itself
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="15dp" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>

Trying to make my entire layout scrollable

I have designed my layout and on smaller phone screens not everything is visible, so I'd like to make it scrollable, could somebody help me with how to go about this? Below is the basic structure of my layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/allowanceroot"
android:background="#drawable/background"
>
--TextView--
--EditText--
--TextView--
--EditText--
--TextView--
--EditText--
</LinearLayout>
Do I just contain my TextViews and EditTexts in a LinearLayout, and then contain that in a ScrollView? Also is there anything I need to do programmatically?
Try wrapping it in a scrollview
https://stackoverflow.com/a/4202608/661079
There is nothing else you need to do
Try like this
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView />
<TextView />
</LinearLayout>
</ScrollView>

Android: EditText on top of WebView?

I would like to imitate the behavior of the default android browser - The EditText (the address bar) on top will start to "disappear" once the user scrolls down. The only thing I can think of right now is to put the EditText and the WebView in a ScrollView but that would create other problems, and is not recommended.
What do you think?
Create a custom View by extending WebView and override onScrollChanged(). With a little calculations you can accomplish your task.
What problems does your ScrollView cause? This one should work fine:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0" android:orientation="vertical">
<ScrollView android:layout_width="fill_parent" android:layout_gravity="top" android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0" android:orientation="vertical">
<EditText android:layout_width="fill_parent" android:id="#+id/editText1" android:text="yourtexthere" android:layout_gravity="bottom" android:layout_height="wrap_content">
</EditText>
<WebView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#+id/myWebView"></WebView>
</LinearLayout>
</ScrollView>
</LinearLayout>

ScrollView Not Responding

I have the following XML and am not doing anything fancy with overriding scrolling behaviors:
<?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" >
<ScrollView
android:id="#+id/myscrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:layout_weight="1">
<ListView
android:id="#+id/mylistview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ScrollView>
<TextView
android:id="#+id/my_empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/my_foo"
android:gravity="center"
android:visibility="gone"
/>
</LinearLayout>
However, while the embedded listview does respond to presses and long presses, it does not scroll. What am I doing wrong?
The trailing TextView is the listview's emptyview.
ScrollView does not play nicely with any other view that scrolls natively, i.e WebView, ListView, etc.
Try a Relative layout and see if this does what you need.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/mylistview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alingParentTop="true"
/>
<TextView
android:id="#+id/my_empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/my_foo"
android:gravity="center"
android:visibility="gone"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
In android it should not put ListView inside a ScrollView. It will not work.
Take the ListView out of the ScrollView. It causes problems, and is unnecessary (ListView handles scrolling on its own.)

Categories

Resources