[英]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.