Reputation: 3591
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!
Upvotes: 0
Views: 1558
Reputation: 3591
got it working after a few rounds. The solution was using a ScrollView then inside that a relativelayout mirroring @Karan_rana's answer.
Upvotes: 1
Reputation: 18499
<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>
Upvotes: 1
Reputation: 4866
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>
Upvotes: 0
Reputation: 2823
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>
Upvotes: 0