Android滚动视图不能很好地适应屏幕

时间:2014-11-26 11:44:28

标签: android xml scrollview android-linearlayout android-layout-weight

我的项目是创建动态的电子邮件字段,从某种意义上说,我可以拥有一个,两个和其他。所以我考虑将整个右侧的细节放在ScrollView中。问题是scroolview永远不会出现,不可滚动,无法弄清楚出了什么问题,我不希望它适合屏幕,但你可以滚动。有人能帮我吗 ?非常感谢

enter image description here

main.xml中

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="10" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="9"
        android:orientation="horizontal"
        android:weightSum="10" >

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:orientation="vertical"
            android:weightSum="10" >

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:scaleType="fitStart"
                android:src="@drawable/user" />
        </LinearLayout>

        <ScrollView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="7" 
            android:fillViewport="true">

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

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="4"
                    android:orientation="horizontal"
                    android:weightSum="10" >

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="5"
                        android:orientation="vertical"
                        android:weightSum="10" >

                        <TextView
                            android:id="@+id/labelname"
                            android:layout_width="match_parent"
                            android:layout_height="0dp"
                            android:layout_weight="3"
                            android:background="@color/gray"
                            android:drawableLeft="@drawable/ic_action_person"
                            android:gravity="left|center_vertical"
                            android:text=" Name"
                            android:textSize="@dimen/campaign_textfontsize_label" />

                        <EditText
                            android:id="@+id/name"
                            android:layout_width="match_parent"
                            android:layout_height="0dp"
                            android:layout_weight="7"
                            android:background="@drawable/edit_text"
                            android:gravity="center_vertical"
                            android:hint="Nome"
                            android:imeOptions="actionDone"
                            android:inputType="textCapSentences|textAutoCorrect"
                            android:singleLine="true"
                            android:textSize="@dimen/campaign_textfontsize" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="5"
                        android:orientation="vertical"
                        android:weightSum="10" >

                        <TextView
                            android:id="@+id/labelsurname"
                            android:layout_width="match_parent"
                            android:layout_height="0dp"
                            android:layout_weight="3"
                            android:background="@color/gray"
                            android:drawableLeft="@drawable/ic_action_person"
                            android:gravity="left|center_vertical"
                            android:text=" Surname"
                            android:textSize="@dimen/campaign_textfontsize_label" />

                        <EditText
                            android:id="@+id/surname"
                            android:layout_width="match_parent"
                            android:layout_height="0dp"
                            android:layout_weight="7"
                            android:background="@drawable/edit_text"
                            android:gravity="center_vertical"
                            android:hint="Surname"
                            android:imeOptions="actionDone"
                            android:inputType="textCapSentences|textAutoCorrect"
                            android:singleLine="true"
                            android:textSize="@dimen/campaign_textfontsize" />
                    </LinearLayout>
                </LinearLayout>

                <TextView
                    android:id="@+id/labelemail"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:background="@color/gray"
                    android:drawableLeft="@drawable/ic_action_email"
                    android:gravity="left|center_vertical"
                    android:text=" E-Mail"
                    android:textSize="@dimen/campaign_textfontsize_label" />

                <EditText
                    android:id="@+id/emailHome"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="3"
                    android:background="@drawable/edit_text"
                    android:gravity="center_vertical"
                    android:hint="E-Mail"
                    android:imeOptions="actionDone"
                    android:inputType="textCapSentences|textAutoCorrect"
                    android:singleLine="true"
                    android:textSize="@dimen/campaign_textfontsize" />

                <EditText
                    android:id="@+id/emailWork"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="3"
                    android:background="@drawable/edit_text"
                    android:gravity="center_vertical"
                    android:hint="E-Mail"
                    android:imeOptions="actionDone"
                    android:inputType="textCapSentences|textAutoCorrect"
                    android:singleLine="true"
                    android:textSize="@dimen/campaign_textfontsize" />

                <EditText
                    android:id="@+id/emailOther"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="3"
                    android:background="@drawable/edit_text"
                    android:gravity="center_vertical"
                    android:hint="E-Mail"
                    android:imeOptions="actionDone"
                    android:inputType="textCapSentences|textAutoCorrect"
                    android:singleLine="true"
                    android:textSize="@dimen/campaign_textfontsize" />

                <EditText
                    android:id="@+id/emailMobile"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="3"
                    android:background="@drawable/edit_text"
                    android:gravity="center_vertical"
                    android:hint="E-Mail"
                    android:imeOptions="actionDone"
                    android:inputType="textCapSentences|textAutoCorrect"
                    android:singleLine="true"
                    android:textSize="@dimen/campaign_textfontsize" />

                <TextView
                    android:id="@+id/labelnumber"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:background="@color/gray"
                    android:drawableLeft="@drawable/ic_action_dial_pad"
                    android:gravity="left|center_vertical"
                    android:text=" Telefono"
                    android:textSize="@dimen/campaign_textfontsize_label" />

                <EditText
                    android:id="@+id/number"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="3"
                    android:background="@drawable/edit_text"
                    android:focusableInTouchMode="true"
                    android:gravity="center_vertical"
                    android:hint="Number"
                    android:imeOptions="actionDone"
                    android:inputType="phone"
                    android:singleLine="true"
                    android:textSize="@dimen/campaign_textfontsize" />
            </LinearLayout>
        </ScrollView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:weightSum="10" >

        <Button
            android:id="@+id/save"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:background="@drawable/color_button"
            android:clickable="true"
            android:drawableStart="@drawable/ic_action_save"
            android:focusable="true"
            android:text="Save"
            android:textColor="#78858B"
            android:textStyle="bold" />

        <Button
            android:id="@+id/delete"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:background="@drawable/color_button"
            android:clickable="true"
            android:drawableStart="@drawable/ic_action_discard"
            android:focusable="true"
            android:text="Delete"
            android:textColor="#78858B"
            android:textStyle="bold" />

        <Button
            android:id="@+id/cancel"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:background="@drawable/color_button"
            android:clickable="true"
            android:drawableStart="@drawable/ic_action_cancel"
            android:focusable="true"
            android:text="Cancel"
            android:textColor="#78858B"
            android:textStyle="bold" />

        <Button
            android:id="@+id/add"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/color_button"
            android:clickable="true"
            android:drawableStart="@drawable/ic_action_add_person"
            android:focusable="true"
            android:textColor="#78858B"
            android:textStyle="bold" />
    </LinearLayout>

</LinearLayout>

3 个答案:

答案 0 :(得分:0)

尝试仅将ScrollView用于各种电子邮件EditText,并为ScrollView提供权重,以便显示多个电子邮件EditText的剩余空间:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.90"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.30"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:scaleType="fitStart"
                android:src="@drawable/user" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.70"
            android:orientation="vertical">

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

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/labelname"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@color/gray"
                        android:drawableLeft="@drawable/ic_action_person"
                        android:gravity="left|center_vertical"
                        android:text=" Name"
                        android:textSize="@dimen/campaign_textfontsize_label" />

                    <EditText
                        android:id="@+id/name"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@drawable/edit_text"
                        android:gravity="center_vertical"
                        android:hint="Nome"
                        android:imeOptions="actionDone"
                        android:inputType="textCapSentences|textAutoCorrect"
                        android:singleLine="true"
                        android:textSize="@dimen/campaign_textfontsize" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/labelsurname"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@color/gray"
                        android:drawableLeft="@drawable/ic_action_person"
                        android:gravity="left|center_vertical"
                        android:text=" Surname"
                        android:textSize="@dimen/campaign_textfontsize_label" />

                    <EditText
                        android:id="@+id/surname"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@drawable/edit_text"
                        android:gravity="center_vertical"
                        android:hint="Surname"
                        android:imeOptions="actionDone"
                        android:inputType="textCapSentences|textAutoCorrect"
                        android:singleLine="true"
                        android:textSize="@dimen/campaign_textfontsize" />
                </LinearLayout>
            </LinearLayout>

            <TextView
                android:id="@+id/labelemail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/gray"
                android:drawableLeft="@drawable/ic_action_email"
                android:gravity="left|center_vertical"
                android:text=" E-Mail"
                android:textSize="@dimen/campaign_textfontsize_label" />

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:fillViewport="true">

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

                    <EditText
                        android:id="@+id/emailHome"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@drawable/edit_text"
                        android:gravity="center_vertical"
                        android:hint="E-Mail"
                        android:imeOptions="actionDone"
                        android:inputType="textCapSentences|textAutoCorrect"
                        android:singleLine="true"
                        android:textSize="@dimen/campaign_textfontsize" />

                    <EditText
                        android:id="@+id/emailWork"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@drawable/edit_text"
                        android:gravity="center_vertical"
                        android:hint="E-Mail"
                        android:imeOptions="actionDone"
                        android:inputType="textCapSentences|textAutoCorrect"
                        android:singleLine="true"
                        android:textSize="@dimen/campaign_textfontsize" />

                    <EditText
                        android:id="@+id/emailOther"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@drawable/edit_text"
                        android:gravity="center_vertical"
                        android:hint="E-Mail"
                        android:imeOptions="actionDone"
                        android:inputType="textCapSentences|textAutoCorrect"
                        android:singleLine="true"
                        android:textSize="@dimen/campaign_textfontsize" />

                    <EditText
                        android:id="@+id/emailMobile"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@drawable/edit_text"
                        android:gravity="center_vertical"
                        android:hint="E-Mail"
                        android:imeOptions="actionDone"
                        android:inputType="textCapSentences|textAutoCorrect"
                        android:singleLine="true"
                        android:textSize="@dimen/campaign_textfontsize" />
                </LinearLayout>
            </ScrollView>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <TextView
                    android:id="@+id/labelnumber"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/gray"
                    android:drawableLeft="@drawable/ic_action_dial_pad"
                    android:gravity="left|center_vertical"
                    android:text=" Telefono"
                    android:textSize="@dimen/campaign_textfontsize_label" />

                <EditText
                    android:id="@+id/number"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/edit_text"
                    android:focusableInTouchMode="true"
                    android:gravity="center_vertical"
                    android:hint="Number"
                    android:imeOptions="actionDone"
                    android:inputType="phone"
                    android:singleLine="true"
                    android:textSize="@dimen/campaign_textfontsize" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.10"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/save"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/color_button"
            android:clickable="true"
            android:drawableStart="@drawable/ic_action_save"
            android:focusable="true"
            android:text="Save"
            android:textColor="#78858B"
            android:textStyle="bold" />

        <Button
            android:id="@+id/delete"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/color_button"
            android:clickable="true"
            android:drawableStart="@drawable/ic_action_discard"
            android:focusable="true"
            android:text="Delete"
            android:textColor="#78858B"
            android:textStyle="bold" />

        <Button
            android:id="@+id/cancel"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/color_button"
            android:clickable="true"
            android:drawableStart="@drawable/ic_action_cancel"
            android:focusable="true"
            android:text="Cancel"
            android:textColor="#78858B"
            android:textStyle="bold" />

        <Button
            android:id="@+id/add"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/color_button"
            android:clickable="true"
            android:drawableStart="@drawable/ic_action_add_person"
            android:focusable="true"
            android:textColor="#78858B"
            android:textStyle="bold" />
    </LinearLayout>
</LinearLayout>

答案 1 :(得分:0)

<ScrollView 
         android:layout_width="match_parent"
          android:layout_height="wrap_content"
        >
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical" >
    <EditText
        android:id="@+id/feedback_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:ems="10"
        android:gravity="center"
        android:hint="Your Feedback"
        android:inputType="textMultiLine"
        android:padding="5dp"
        android:background="@drawable/edittext_feedback"
        android:textColor="#666"
        android:typeface="serif" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/feedback_email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:ems="10"
        android:gravity="center"
        android:hint="Your Email Address"
        android:inputType="textEmailAddress"
        android:padding="5dp"
        android:textColor="#666"
        android:typeface="serif"
        android:background="@drawable/edittext_feedback"
         />

    <Button
        android:id="@+id/feedback_submit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:background="@drawable/button_shape"
        android:padding="15dp"
        android:text="Submit Feedback"
        android:textColor="#666"
        android:typeface="monospace" />
</LinearLayout>
</ScrollView>

查看此代码并分析它是否对您有所帮助。而且scrollview必须有一个孩子。

答案 2 :(得分:0)

**指&GT;将线性布局作为父级,并将视图滚动为子级。

  

的xmlns:机器人= “http://schemas.android.com/apk/res/android”                        机器人:方向=“垂直”                       机器人:layout_width = “FILL_PARENT”                       机器人:layout_height = “FILL_PARENT” &GT;

     

             

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/feedback_email"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:ems="10"
    android:gravity="center"
    android:hint="Your Email Address"
    android:inputType="textEmailAddress"
    android:padding="5dp"
    android:textColor="#666"
    android:typeface="serif"
    android:background="@drawable/edittext_feedback"
     />

<Button
    android:id="@+id/feedback_submit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_margin="10dp"
    android:background="@drawable/button_shape"
    android:padding="15dp"
    android:text="Submit Feedback"
    android:textColor="#666"
    android:typeface="monospace" /> </LinearLayout> </ScrollView>
     

**