[英]Android scroll view does not work well fits on the screen when it should not
My project is to create the email field dynamic , in the sense that I can have one, two , and others. 我的项目是创建动态的email字段,从这个意义上讲,我可以拥有一个,两个和其他字段。 So I thought about putting the whole right side with the details in a ScrollView .
因此,我考虑将整个右侧和详细信息放在ScrollView中。 The problem is that the scroolview never appears , is not scrollable and can not figure out what is wrong ,I would not want that would fit onto the screen but you can scroll .
问题是scroolview永远不会出现,无法滚动并且无法找出问题所在,我不希望它适合屏幕,但是您可以滚动。 can someone help me ?
有人能帮我吗 ? thanks so much
非常感谢
main.xml 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>
Try to only use ScrollView for various email EditText and also given weight to ScrollView so it will taken rest space for showing multiple email EditText : 尝试仅对各种电子邮件EditText使用ScrollView,还要对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>
<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>
see this code and analyze if it might helpful to you. 查看此代码并分析它是否可能对您有帮助。 and also scrollview must have one child .
并且scrollview必须有一个孩子。
**> > Take Linear layout as a parent, and scroll view as a child. **>>将线性布局作为父级,并滚动视图作为子级。
xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
xmlns:android =“ http://schemas.android.com/apk/res/android” android:orientation =“垂直” android:layout_width =“ fill_parent” android:layout_height =“ fill_parent”>
<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>
**
**
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.