焦点上的EditText向上滚动而不调整其他视图的大小

时间:2014-01-29 08:40:40

标签: android xml android-edittext scrollview adjustpan

我正在尝试使用EditText字段在选中时滚动我的cameraPreview。但是现在它正在调整cameraPreview的大小。我会满足于adjustPan行为,但我希望actionBar保持在屏幕上。我怀疑它可以用scrollView完成但是我不能阻止cameraPreview调整大小。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >
    <FrameLayout
    android:id="@+id/cameraPreview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent" >

    </FrameLayout>

<!-- Fix for black overlay on menu -->
<FrameLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="@android:color/transparent" >
</FrameLayout>
<ScrollView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:isScrollContainer="true"
        >
      <EditText
        android:id="@+id/inputCode"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@color/White"
        android:ems="10"
        android:inputType="textNoSuggestions"
        android:maxLines="1"
        android:textColor="@color/Green"
        android:textSize="32sp"
        android:layout_alignParentBottom="true" >

    </EditText>
 </ScrollView>

deformed apple

3 个答案:

答案 0 :(得分:0)

最后决定滚动整个视图,包括操作栏

答案 1 :(得分:0)

我一直在寻找解决方案,最后我得到了它;

很简单,

首先,使用scroll_view作为具有edit_text子项的View;

其次,使用Relative_Layout(Linear_Layout无用)作为Scroll_View的子项

然后,你可以看到它有效 注意:(1)不要使用layout_align_Parent_Bottom,而是使用用户layout_below        (2)您无需指定window_Soft_Input_Model,默认为OK;

这是示例

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rootlinearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="500dp"
    android:text="@string/hello_world" >

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

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="64dp"
            android:text="Button1" />

        <Button
            android:id="@+id/button6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button6" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button2" />

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button3" />

        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button4" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/scrollView1"
            android:ems="10" >
        </EditText>

        <Button
            android:id="@+id/button8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button8" />

        <Button
            android:id="@+id/button9"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button9" />

        <Button
            android:id="@+id/button10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button10" />

        <Button
            android:id="@+id/button5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button5" />
    </LinearLayout>
</ScrollView>

<LinearLayout
    android:id="@+id/captionbottomrelativelayout"
    android:layout_width="320dp"
    android:layout_height="44dp"
    android:layout_below="@+id/scrollView1"
    android:orientation="horizontal" >

    <Button
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:text="Button" />`enter code here`
</LinearLayout>

`在这里输入代码

答案 2 :(得分:0)

android:windowSoftInputMode="stateHidden|adjustResize|adjustPan"

在清单活动中添加以上行。

相关问题