2013-03-16 36 views
0

我一直在搜索Google和stackoverflow一段時間,並沒有發現任何回答我的問題。Android Webview與底部的孩子

我想知道在WebView的底部放置一個LinearLayout(像素沒有特定的已知高度)。此LinearLayout稍後將填入一個片段,其中包含WebView中顯示的文章的註釋。

問題的問題是WebView幾乎總是大於屏幕,因此用戶必須滾動才能閱讀完整文章。在滾動的底部,我想插入CommentsFragment(通過LinearLayout,它需要一些參數,因此不能直接從XML中加載)。

我試過了一堆解決方案,但所有這些都使LinearLayout堅持佈局的底部,而不是在WebView的底部。

我當前的代碼如下,當然不工作:

<?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> 

謝謝您的幫助!

+0

你是否想要評論frgament會低於webview? – 2013-03-16 12:23:15

+0

是的正確,我還沒有解決它 – 2013-03-18 09:50:04

+0

試試我的答案在下面。 – 2013-03-18 10:11:13

回答

0

幾個回合後才能正常工作。解決方案是使用ScrollView,然後在裏面的相關佈局鏡像@ Karan_rana的答案。

0

如果你想要把下面的Web視圖的評論片段,那麼你可以嘗試如下,並告訴我,如果你的作品

<?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> 
+0

嗨,不抱歉它不工作,它卡在屏幕的底部,而不是在webview的底部。 – 2013-03-16 12:47:27

0

試試這個,確保有layout_height="wrap_content"在你的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> 
+0

我必須現在走,但稍後會嘗試。我認爲如果圖像是例如圖像,則在webview中水平滾動會出現問題。太寬,但我會嘗試。 – 2013-03-16 12:53:32

+0

這個解決方案不會解決你的WebView的水平滾動問題,也許你可以嘗試一些CSS魔術來使它適合,如果你控制輸入 – minipif 2013-03-16 13:00:30

+0

嗨,這不起作用,對不起,它只是做了一個很長的滾動視圖,沒有任何東西在底部。 – 2013-03-17 13:05:40

0
<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> 
+0

嗨,對不起,這也不起作用。你可以在這裏發佈這個代碼的工作示例嗎?您不必使用評論片段,只需將其設置爲固定高度即可。感謝您的帖子 – 2013-03-19 11:50:13