ScrollView не работает - PullRequest
       2

ScrollView не работает

4 голосов
/ 31 марта 2012

Это должно быть легко, я знаю !!! Я смотрел учебник, искал прибл. 2 часа и попробовал 15 различных методов (может быть, больше) и до сих пор не могу заставить его работать.

В моем приложении, когда я фокусируюсь / выбираю EditText, и появляется клавиатура, я не могу прокрутить вниз, чтобы ввести другой текст

AndroidManifest.xml > активность установлена ​​на android: windowSoftInputMode = "AdjustPan"

вот макет > main.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg"
    android:orientation="vertical"
    android:padding="20dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp" >

        <TextView
            android:id="@+id/txtProduct1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Produkt 1"
            android:textColor="#FFFFFF"
            android:textSize="28dp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/txtInfo1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginLeft="5dp"
            android:gravity="right"
            android:text="cena / hmot: 0 eur"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="#EEEEEE"
            android:width="140dp" />
    </LinearLayout>

    <EditText
        android:id="@+id/txtPrice1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="10dp"
        android:ems="10"
        android:hint="Cena"
        android:inputType="numberDecimal" >
    </EditText>

    <EditText
        android:id="@+id/txtWeight1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:ems="10"
        android:hint="Hmotnosť"
        android:inputType="numberDecimal" />

    <ImageView
        android:id="@+id/imgResult"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/question" />

    <EditText
        android:id="@+id/txtPrice2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="20dp"
        android:ems="10"
        android:hint="Cena"
        android:inputType="numberDecimal" />

    <EditText
        android:id="@+id/txtWeight2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:ems="10"
        android:hint="Hmotnosť"
        android:inputType="numberDecimal" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/txtInfo2"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginRight="5dp"
            android:text="cena / hmot: 0 eur"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="#EEEEEE"
            android:width="140dp" />

        <TextView
            android:id="@+id/txtProduct2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Produkt 2"
            android:textColor="#FFFFFF"
            android:textSize="28dp"
            android:textStyle="bold" />
    </LinearLayout>

    <Button
        android:id="@+id/btnOK"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="15dp"
        android:height="80dp"
        android:text="OK"
        android:textColor="#264865"
        android:textSize="24dp"
        android:textStyle="bold"
        android:width="160dp" />
 </LinearLayout>

</ScrollView>

Ответы [ 3 ]

3 голосов
/ 31 марта 2012

Пара вещей:

  1. Убедитесь, что у ScrollView только один дочерний элемент,

  2. Как уже упоминалось, убедитесь, что у вас есть закрывающий тег

  3. Следующий код работал у меня ...

<?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"
  android:fillViewport="true" >

  <LinearLayout
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" >

          <!--I added more views here! -->

  </LinearLayout>
</ScrollView>

Надеюсь, это поможет.

----------------------------------------------- -------------------------------------------

Обновление из комментариев ... Снимок экрана, когда я копирую и вставляю ваш код (на Samsung Galaxy S). Рабочая!

Your layout on a Galaxy S


1 голос
/ 26 августа 2014

В моем случае в ScrollView у меня был OnTouchListener, который возвращал значение true в методе onTouch. Это сломало прокрутку. Изменение его на возвращаемое ложное исправило проблему.

1 голос
/ 31 марта 2012

Наконец-то вы не засвидетельствовали </ScrollView>, просто добавьте, и вы сделали.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...