当内部的线性布局时,Scrollview无法正常工作

时间:2016-04-13 11:12:37

标签: android android-layout scrollview

  

我只是在scrollview中放置一个线性布局,不知道为什么它不起作用。

当键盘打开时,滚动条根本不显示。当我将一个文本框移动到另一个文本框时,会有一个提交按钮,当我在小尺寸设备上运行时,该按钮不显示。

package com.company;
import java.io.*;


public class Main implements Serializable {

    public static void main(String [] args) {
        Employee e = new Employee();
        e.name = "ADS";
        e.address = "Qwerty";
        e.SSN = 1856;
        e.number = 91246;

        try {
            FileOutputStream fileOut =
                new FileOutputStream("c:\\TSTPersistentStore.ser",true);
            AppendingObjectOutputStream appendingObjectOutputStream=new AppendingObjectOutputStream(fileOut);
            ObjectOutputStream out = new ObjectOutputStream(fileOut);
            appendingObjectOutputStream.writeStreamHeader();
            appendingObjectOutputStream.writeObject(e);
            appendingObjectOutputStream.close();
            fileOut.close();
            System.out.printf("Serialized data is appended in /tmp/employee.ser");
        } catch(IOException i) {
            i.printStackTrace();
        }
    }
}


package com.company;
import java.io.*;

public class AppendingObjectOutputStream extends ObjectOutputStream {

    public AppendingObjectOutputStream(OutputStream out) throws IOException {
        super(out);
    }

    @Override
    protected void writeStreamHeader() throws IOException {
        reset();
    }

}


package com.company;

public class Employee implements java.io.Serializable {
    public String name;
    public String address;
    public transient int SSN;
    public int number;

    public void mailCheck() {
        System.out.println("Mailing a check to " + name + " " + address);
    }
}

package com.company;


import java.io.*;
public class DeserializeDemo {
    public static void main(String [] args) {
        Employee e = null;
        try {
            FileInputStream fileIn = new FileInputStream("c:\\TSTPersistentStore.ser");
            ObjectInputStream in = new ObjectInputStream(fileIn);
            e = (Employee) in.readObject();
            e = (Employee) in.readObject();
            in.close();
            fileIn.close();
        } catch(IOException i) {
            i.printStackTrace();
            return;
        } catch(ClassNotFoundException c) {
            System.out.println("Employee class not found");
            c.printStackTrace();
            return;
        }
        System.out.println("Deserialized Employee...");
        System.out.println("Name: " + e.name);
        System.out.println("Address: " + e.address);
        System.out.println("SSN: " + e.SSN);
        System.out.println("Number: " + e.number);
    }
}

3 个答案:

答案 0 :(得分:0)

尝试将scrollview放在另一个线性布局中并尝试

答案 1 :(得分:0)

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/parentLin"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="//define in dp"
    android:scrollbars="vertical"
    android:fillViewport="true">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <EditText
        android:id="@+id/editTextName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/editboxshap"
        android:textColorHint="#2b2b2b"
        android:textColor="#2b2b2b"
        android:ems="10"
        android:hint="Name"
        android:inputType="textPersonName"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceMedium">

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editPhone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/editboxshap"
        android:ems="10"
        android:textColor="#2b2b2b"
        android:hint="Phone No."
        android:inputType="phone"
        android:textColorHint="#2b2b2b"
        android:maxLength="12"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editEmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/editboxshap"
        android:textColor="#2b2b2b"
        android:ems="10"
        android:textColorHint="#2b2b2b"
        android:hint="E-mail"
        android:inputType="textEmailAddress"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editComment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/editboxshap"
        android:ems="10"
        android:gravity="start"
        android:textColor="#2b2b2b"
        android:hint="Comments"
        android:textColorHint="#2b2b2b"
        android:inputType="textMultiLine"
        android:lines="3"
        android:maxLength="500"
        android:textAppearance="?android:attr/textAppearanceMedium" />



</LinearLayout>
</ScrollView>
<RelativeLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="center">

        <Button
    android:id="@+id/btnSubmit"
    android:layout_width="match_parent"
    android:layout_height="35dp"
    android:layout_gravity="center_horizontal"
    android:layout_marginBottom="5dp"
    android:layout_marginTop="20dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:background="@drawable/button_shape"
    android:text="SUBMIT"
    android:textColor="@color/white" />

    </RelativeLayout>

</RelativeLayout>

并且您必须在清单文件中使用您的活动

指定以下代码行
   android:windowSoftInputMode="adjustResize" 

答案 2 :(得分:0)

在你的活动/片段

上试试这个..
getActivity().getWindow()
        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE |
                          WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);