android - 修复安卓错误 "Invalid layout param"

标签 android

嘿,我是 Android 编程的新手,我的代码中有几个错误。我知道我搜索过类似的错误,但没有特别针对我的特定代码。

具体报错的行如下:

android:layout_alignLeft="@+id/edit_message"-Edittext:layout_align_left 中的布局参数无效

android:layout_below="@+id/edit_message"-Edittext:layout_below 中的布局参数无效

android:layout_alignBottom="@+id/editText1"- 编辑文本中的布局参数无效: android:layout_alignParentRight="true"-Edittext 中的布局参数无效:

这是我所有的代码,请告诉我我需要更正哪一部分来修复错误。

<LinearLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.discountprice2.MainActivity$PlaceholderFragment" >
    <EditText
    android:id="@+id/edit_message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:hint="@string/edit_message"
    android:inputType="text|number" >

        <EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/edit_message"
    android:layout_below="@+id/edit_message"
    android:ems="10"
    android:hint="@string/edit_message1"
    android:inputType="numberDecimal" />

        <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/editText1"
    android:layout_alignParentRight="true"
    android:onClick="sendMessage"
    android:text="@string/calc" />
    </EditText>
    </LinearLayout> 

最佳答案

那是因为android:layout_alignLeftandroid:layout_below等只绑定(bind)到RelativeLayout而不是LinearLayout,LinearLayout 只有垂直和水平两个方向,不支持每个 View 的布局对齐。

解决方法:

将父布局更改为 RelativeLayout

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.discountprice2.MainActivity$PlaceholderFragment" >

         /////////YOUR CONTENT HERE///////////////

</RelativeLayout >

关于android - 修复安卓错误 "Invalid layout param",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25299639/

相关文章:

java - 找不到适合 requestLocationUpdates 的方法

java - 在 XML 文件中嵌入 base64 编码的图像 (android-java)

android - 得到运行时错误 : java. lang.RuntimeException : java. lang.NoSuchMethodException

android - 如何使 TextView 显示来自 asyncTask 类的值

android - 如何使用 azure sql 连接和访问(如编辑)

android - 使用Neshan Maps Android SDK时如何减小apk大小?

android - 改造后的 Rxjava2

java - 小米设备允许应用程序在后台运行时弹出窗口

java - 为什么 Android Pie 需要双击才能保持对作为 recyclerView 项目部分的编辑文本的关注?如何解决?

java - 软键盘监听器