WebView и расположение кнопок делают кнопки невидимыми - PullRequest
0 голосов
/ 25 сентября 2010

У меня есть следующий макет:

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

2 голосов
/ 25 сентября 2010

Используйте 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>

android:layout_alignParentBottom="true" гарантирует, что кнопки всегда имеют достаточно места.

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

android:layout_alignParentTop="true"`

Редактировать:

<?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 голосов
/ 30 января 2011

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

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

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

...