[英]ScrollView doesn't work
我知道應該很容易!!! 我看了教程,搜索了大約。 2小時,嘗試了15種不同的方法(可能更多),但仍然無法正常工作。
在我的應用中,當我聚焦/選擇EditText並彈出鍵盤時,無法向下滾動以輸入其他文本
AndroidManifest.xml > 活動設置為android:windowSoftInputMode =“ adjustPan”
這是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>
幾件事情:
確保ScrollView只有一個孩子,
如前所述,請確保您有一個結束標記
以下代碼為我工作...
<?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上)時的屏幕截圖。 工作!
就我而言,我在ScrollView上有一個OnTouchListener,在onTouch方法中返回true。 這打破了滾動。 將其更改為false可以解決此問題。
最后您還沒有弄清</ScrollView>
,只需添加就可以了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.