Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
642 views
in Technique[技术] by (71.8m points)

android - Relativelayout inside Scrollview not working

I have a relative layout inside a scrollview and I can't get it to work.I tried setting my relative layout's height to wrap_content but it doesn't work also. I can get it to work with linear layout but I don't want to use it for some reason.

Here is my xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true">

<RelativeLayout
    android:id="@+id/container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF"
    android:orientation="vertical"
    android:padding="14dp">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:inputType="textPersonName"
        android:id="@id/feedback_name"
        android:hint="Name"
        android:textColor="#000000"
        android:layout_alignParentTop="true"
        android:ems="10"
        android:maxHeight="48dp"
        android:textSize="14sp" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:inputType="textEmailAddress"
        android:ems="10"
        android:maxHeight="48dp"
        android:id="@id/feedback_email"
        android:hint="Your email (optional)"
        android:textColor="#000000"
        android:layout_below="@id/feedback_name"
        android:textSize="14sp" />

    <Spinner
        android:id="@id/feedback_concern"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:minHeight="48dp"
        android:layout_below="@id/feedback_email" />

    <EditText
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:inputType="textMultiLine"
            android:ems="10"
            android:id="@id/feedback_message"
            android:hint="Message"
            android:textColor="#000000"
        android:layout_weight="1"
        android:minHeight="70dp"
            android:gravity="top"
            android:textSize="14sp"
            android:layout_below="@id/feedback_concern"
        android:layout_above="@id/feedback_send"
/>


    <Button
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:text="Send"
        android:maxHeight="48dp"
        android:id="@id/feedback_send"
        android:background="@color/light"
        android:textColor="#FFFFFF"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/progressBar"
        android:visibility="invisible"
        android:layout_gravity="center_horizontal"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="error"
        android:fontFamily="sans-serif-light"
        android:id="@id/errorText"
        android:visibility="invisible"
        android:layout_gravity="center_horizontal"
        android:textColor="@android:color/black"
        android:layout_below="@id/feedback_message"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:gravity="center"
        android:singleLine="true" />

</RelativeLayout>
</ScrollView>

Portrait:

enter image description here

Landscape:

enter image description here

You can see that the message edittext disappeared when I go to landscape mode and the layout doesn't scroll

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Apply the scrollview from top to message edittext.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical"
android:padding="14dp" >

<ScrollView
    android:id="@+id/scroll"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/feedback_send"
    android:fillViewport="true" >

    <RelativeLayout
        android:id="@+id/container"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <EditText
            android:id="@+id/feedback_name"
            android:layout_width="fill_parent"
            android:layout_height="48dp"
            android:layout_alignParentTop="true"
            android:ems="10"
            android:hint="Name"
            android:inputType="textPersonName"
            android:maxHeight="48dp"
            android:textColor="#000000"
            android:textSize="14sp" />

        <EditText
            android:id="@+id/feedback_email"
            android:layout_width="fill_parent"
            android:layout_height="48dp"
            android:layout_below="@id/feedback_name"
            android:ems="10"
            android:hint="Your email (optional)"
            android:inputType="textEmailAddress"
            android:maxHeight="48dp"
            android:textColor="#000000"
            android:textSize="14sp" />

        <Spinner
            android:id="@+id/feedback_concern"
            android:layout_width="fill_parent"
            android:layout_height="48dp"
            android:layout_below="@id/feedback_email"
            android:minHeight="48dp" />

        <EditText
            android:id="@+id/feedback_message"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/feedback_concern"
            android:ems="10"
            android:gravity="top"
            android:hint="Message"
            android:inputType="textMultiLine"
            android:minHeight="70dp"
            android:textColor="#000000"
            android:textSize="14sp" />
    </RelativeLayout>
</ScrollView>

<Button
    android:id="@id/feedback_send"
    android:layout_width="fill_parent"
    android:layout_height="48dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:background="@android:color/background_dark"
    android:maxHeight="48dp"
    android:text="Send"
    android:textColor="#FFFFFF" />

<ProgressBar
    android:id="@+id/progressBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center_horizontal"
    android:visibility="invisible" />

<TextView
    android:id="@+id/errorText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_below="@+id/scroll"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center_horizontal"
    android:gravity="center"
    android:singleLine="true"
    android:text="error"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@android:color/black"
    android:visibility="invisible" />

</RelativeLayout>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...