键入时Android按钮重叠文本布局

时间:2016-04-04 19:12:19

标签: android xml layout

我正在编写一个Android应用程序,其初始屏幕工作正常。问题是,在键入时,按钮会与文本重叠,如下所示:

enter image description here

以下是代码:

module.exports = {
  full: function(){
      return this.firstname + " " + this.lastname;
  },
  formal: function(){
      return "Mr. " + this.lastname;
  }
};

任何帮助都将非常感谢,提前感谢。

3 个答案:

答案 0 :(得分:1)

解决此问题的一种方法是在活动代码中使用android:windowSoftInputMode="adjustNothing"

<activity name="YourActivity"
        android:windowSoftInputMode="adjustNothing">
        ...
</activity>

但是,请记住,在这种情况下,注册按钮将被键盘覆盖。

答案 1 :(得分:1)

您已在页面中相对于另一个视图设置每个视图。 您最好将所有元素放在页面中,相对于一个元素或相对于主布局。 这个问题是因为使用&#34;相对布局&#34;。  另一种选择是在相对布局中使用更简单的布局,如线性布局,以简化操作。

答案 2 :(得分:1)

当我开始使用Android开发时,我也习惯使用RelativeLayout(我不是专家,我只是告诉我的经验)。首先,它看起来是最合适的布局,但你应该记住的一件事是:让系统处理你的事情,换句话说,RelativeLayout完全依赖于你所说的,因此,如果不考虑新的屏幕分辨率或旧的分辨率,整个布局可能会变得一团糟。

目标是,在不使用特定参数的情况下告诉Android你想要什么(或者至少试着避​​免这些参数)。我同意@klaymen:对于不同的方向,你应该使用的不仅仅是一个布局。

仅举个例子,请参阅下面的代码(它是您的代码的重拍):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.app.InitialActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Welcome to app"
        android:id="@+id/textViewTitle" />

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

        <EditText
            android:id="@+id/editTextEmail"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="textEmailAddress"
            android:textSize="17sp"
            android:hint="Enter your email"
            android:ems="10" />

        <EditText
            android:id="@+id/editTextPassword"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            android:textSize="17sp"
            android:hint="Enter your password"
            android:ems="10" />

        <Button
            android:id="@+id/loginButton"
            android:text="Login"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/editTextPassword" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom"
        android:weightSum="2"
        android:orientation="horizontal">

        <Button
            android:id="@+id/registerButton"
            android:text="Register"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>

        <Button
            android:id="@+id/forgotPasswordButton"
            android:text="Forgot Password?"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>
    </LinearLayout>
</LinearLayout>

这里有一些重要的东西,可以在下次尝试中帮助你很多(在上面的代码中查找这些属性):

  • 机器人:layout_gravity;

      

    儿童向其父母提供的标准重力常数。定义子视图在其封闭布局中在X轴和Y轴上的定位方式。

  • 机器人:重力;

      

    指定对象如何在其自己的边界内在X轴和Y轴上定位其内容。

  • 机器人:weightSum;

      

    定义最大重量总和。如果未指定,则通过添加所有子项的layout_weight来计算总和。例如,通过给予layout_weight为0.5并将weightSum设置为1.0,可以使单个子节点占总可用空间的50%。   必须是浮点值,例如&#34; 1.2&#34;。   这也可以是对资源的引用(格式为&#34; @ [package:]类型:name&#34;)或主题属性(格式为&#34;?[package:] [type:] name& #34;)包含此类型的值。   这对应于全局属性资源符号weightSum。

  • 机器人:layout_weight;

      

    LinearLayout还支持使用android:layout_weight属性为各个孩子分配权重。该属性赋予&#34;重要性&#34;根据它应占据屏幕的空间大小来定义视图。较大的权重值允许它扩展以填充父视图中的任何剩余空间。子视图可以指定权重值,然后视图组中的任何剩余空间将按其声明权重的比例分配给子项。默认权重为零。

我希望能帮到你。还有一件事情是使用你的IDE,生成一些例子,看看它们是如何工作的(它们曾经是动态的),我很确定你会通过这个练习学到很多东西。

祝你好运!

相关问题