首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在android移动应用程序中,视图在从纵向更改为横向时隐藏

问在android移动应用程序中,视图在从纵向更改为横向时隐藏
EN

Stack Overflow用户
提问于 2015-06-28 18:20:50
回答 2查看 728关注 0票数 0

我的应用程序中有一个活动。在这里,我使用一些编辑框从用户那里获取了一些值。问题是,如果手机的方向是纵向的,那么我可以看到所有的EditBoxes和按钮,但当方向改为横向时,按钮会隐藏起来,我只能看到前3个编辑框,其他什么也看不见。所有我想要的是,如果这样的情况出现,布局的大小超过了手机的高度,那么滚动应该会出现,这样我就可以向下滚动看到下面的字段和按钮。有没有更好的方法?(对横向模式使用不同的布局将导致重新创建我不想要的活动)

下面是我的活动的代码

代码语言:javascript
复制
<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="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.name.package.service">


<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="@dimen/title_text_size"
    android:textStyle="bold"
    android:gravity="center_horizontal"
    android:id="@+id/tv_lable"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tv_serivce_description"
    android:gravity="left"
    android:text="@string/plumber_service_description"
    android:textSize="@dimen/description_text_size"
    android:layout_marginTop="@dimen/large_margin"
    android:layout_below="@id/tv_book_service_title_lable"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Name :"
    android:id="@+id/tv_customer_name_label"
    android:layout_below="@id/tv_serivce_description"
    android:layout_marginTop="@dimen/huge_spacing"
    android:textSize="@dimen/label_text_size"
    />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/et_customer_name"
    android:layout_alignBottom="@id/tv_customer_name_label"
    android:layout_toRightOf="@id/tv_customer_name_label"
    android:layout_marginLeft="@dimen/normal_margin"
    android:hint="fiil your name"
    android:gravity="center_horizontal"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Email :"
    android:id="@+id/tv_customer_email_label"
    android:layout_below="@id/tv_customer_name_label"
    android:layout_marginTop="@dimen/large_spacing"
    android:textSize="@dimen/label_text_size"
    />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/et_customer_email"
    android:layout_alignBottom="@id/tv_customer_email_label"
    android:layout_toRightOf="@id/tv_customer_email_label"
    android:layout_marginLeft="@dimen/normal_margin"
    android:hint="fiil your email"
    android:gravity="center_horizontal"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Contact :"
    android:id="@+id/tv_customer_contact_label"
    android:layout_below="@id/tv_customer_email_label"
    android:layout_marginTop="@dimen/large_spacing"
    android:textSize="@dimen/label_text_size"
    />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/et_customer_contact"
    android:layout_alignBottom="@id/tv_customer_contact_label"
    android:layout_toRightOf="@id/tv_customer_contact_label"
    android:layout_marginLeft="@dimen/normal_margin"
    android:hint="fiil your email"
    android:gravity="center_horizontal"
    android:marqueeRepeatLimit="marquee_forever"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tv_service_description_label"
    android:text="Description"
    android:textSize="@dimen/label_text_size"
    android:layout_below="@id/tv_customer_contact_label"
    android:layout_marginTop="@dimen/large_spacing"
    />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/et_service_description"
    android:layout_below="@id/tv_service_description_label"
    android:layout_marginTop="@dimen/large_margin"
    android:hint="What service you need ?"
    />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Book Service"
    android:gravity="center_horizontal"
    android:layout_below="@id/et_service_description"
    android:layout_marginTop="@dimen/large_margin"
    android:layout_centerHorizontal="true"
    />

​

我还在清单文件中使用了以下活动设置

代码语言:javascript
复制
android:configChanges="orientation|keyboardHidden|screenSize"
        android:launchMode="singleTop"

提前感谢您分享knowledge ....:D

EN

回答 2

Stack Overflow用户

发布于 2015-06-28 18:25:44

将您的布局包装在Scrollview中,即RelativeLayout。如果布局不适合窗口,则启用滚动,以便您滚动和查看所有视图,否则它们将在屏幕上不可见。

用法

代码语言:javascript
复制
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/ScrollViewid"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 -------add your RelativeLayout ------
</ScrollView>

ScrollView是一个FrameLayout,这意味着您应该在其中放置一个包含要滚动的整个内容的子项;这个子项本身可能是一个具有复杂对象层次结构的布局管理器。经常使用的子项是垂直方向的LinearLayout,表示用户可以滚动浏览的顶层项的垂直数组。

票数 1
EN

Stack Overflow用户

发布于 2015-06-28 18:25:21

请不要使用RelativeLayout而使用LinearLayout,它会解决您的问题

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31098663

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档