ScrollView doesn't work

空扰寡人 提交于 2019-12-23 10:08:49

问题


It should be easy I know!!! I watched tutorial, searched for approx. 2 hours and tried like 15 different methods (maybe more) and still can't get it to work.

In my app when I focus/select EditText and keyboard pops out I can't scroll down to input other text

AndroidManifest.xml > activity set to android:windowSoftInputMode="adjustPan"

here is the layout>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>

回答1:


Couple of things:

  1. Make sure the ScrollView only has one child,

  2. As already mentioned, make sure you have a closing tag

  3. The following code worked for me...

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

Hope this helps.

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

Update from comments... Screenshot of when I copy and pasted your code (on a Samsung Galaxy S). Working!





回答2:


You haven't witten </ScrollView> at last, Just Add and Ya it is done.




回答3:


In my case, I had an OnTouchListener on the ScrollView that returned true in the onTouch method. This broke scrolling. Changing it to return false fixed the problem.



来源:https://stackoverflow.com/questions/9956106/scrollview-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!