2010-09-25 2 views
0

я получил следующую схему:WebView и кнопка расположение делают кнопки невидимых

<?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="wrap_content" 
       android:orientation="vertical"> 

    <WebView xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/webview" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
    /> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 

     <Button android:id="@+id/back" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:text="Back" /> 

     <Button android:id="@+id/page_number" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:text="1/100" /> 

     <Button android:id="@+id/next" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:text="Next" /> 
    </LinearLayout> 
</LinearLayout> 

что приводит к следующим

alt text

Как сделать кнопки подходят к экрану и остановок WebView отталкивает их?

ответ

2

Использование RelativeLayout. Заверните RelativeLayout вокруг кнопок, как это:

<RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true"> 
    <Button android:id="@+id/back" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text="Back" 
      android:layout_alignParentLeft="true" /> 

    <Button android:id="@+id/page_number" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text="1/100" /> 

    <Button android:id="@+id/next" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text="Next" /> 
    </RelativeLayout> 

The android:layout_alignParentBottom="true" убеждается кнопки всегда есть достаточно места.

Рассмотрите возможность использования RelativeLayout вокруг WebView и использования:

android:layout_alignParentTop="true"` 

Edit:

<?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" 
      android:orientation="vertical"> 
<RelativeLayout android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_alignParentTop="true"> 

<WebView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/webview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
/> 
</RelativeLayout> 

<RelativeLayout android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:layout_alignParentBottom="true"> 

    <Button android:id="@+id/back" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Back" 
      android:layout_alignParentLeft="true" /> 

    <Button android:id="@+id/page_number" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="1/100" 
      android:layout_toRightOf="@+id/back" /> 

    <Button android:id="@+id/next" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Next" 
      android:layout_toRightOf="@+id/page_number" /> 
</RelativeLayout> 
</RelativeLayout> 
+0

Теперь они полностью ушли: P – mlevit

+0

Посмотрите еще раз. – Wroclai

0

Я, имеющий точно такую ​​же проблему, кроме я использую TextView ниже моей WebView и а второй WebView над основным WebView, все необходимое для нашей чат-программы. TextView продолжает отталкиваться от WebView.

Я пробовал предлагаемый переключатель RelativeLayout, также попробовал TableLayout и вложенные LinearLayouts, все с тем же эффектом. Единственное, что работает, - это исправить размер пикселя WebView [который поднимает волосатую проблему обработки onConfigurationCahnge()] или возиться с layout_weight. layout_weight имеет схожие проблемы, хотя, поскольку изменения или размер веб-страницы меняются, окружающие элементы управления сжимаются.

Похоже, если я хочу, чтобы он работал точно в одну сторону, небольшой веб-просмотр вверху, основной веб-просмотр и текстовое изображение, мне нужно будет исправить размер пикселя веб-просмотра и обрабатывать их изменение размера в режиме загрузки (для разных экраны) и onConfigurationChange(), когда экран поворачивается.

Смежные вопросы