Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“修复android错误”;无效的布局参数";_Android - Fatal编程技术网

“修复android错误”;无效的布局参数";

“修复android错误”;无效的布局参数";,android,Android,嘿,我对android编程相当陌生,我的代码中有几个错误。我知道我在搜索时也遇到过类似的错误,但对我的特定代码没有特别的错误 具体行及其特定错误如下所示: android:layout_alignLeft=“@+id/edit_message”-编辑文本中的布局参数无效:layout_align_left android:layout_below=“@+id/编辑_消息”-EditText:layout_below中的布局参数无效 android:layout_alignBottom=“@+id

嘿,我对android编程相当陌生,我的代码中有几个错误。我知道我在搜索时也遇到过类似的错误,但对我的特定代码没有特别的错误

具体行及其特定错误如下所示:

android:layout_alignLeft=“@+id/edit_message”-编辑文本中的布局参数无效:layout_align_left

android:layout_below=“@+id/编辑_消息”-EditText:layout_below中的布局参数无效

android:layout_alignBottom=“@+id/editText1”-EditText中的布局参数无效: android:layout\u 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\u alignLeft
android:layout\u lower
等仅限于
RelativeLayout
而非
LinearLayout
,LinearLayout只有两个方向,即垂直方向和水平方向。它不支持每个视图的布局对齐

解决方案:

将父布局更改为
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:layout_alignLeft="@+id/edit_message"

android:layout_below="@+id/edit_message"


android:layout_alignBottom="@+id/editText1"


android:layout_alignParentRight="true"

/////////你的内容在这里///////////////

使用相对布局而不是线性布局

布局左对齐
使视图的左边缘与ID用作参数的视图的左边缘匹配

layout\u toLeftOf
将视图放置在使用ID的视图的左侧(右边缘将与另一个视图的左边缘对齐)

有关其他相关布局参数,请访问此处:


您使用的参数用于相对布局,而不是线性布局。将线性布局更改为相对布局。

可能的解决方案:

  • 线性布局
    更改为
    相对布局
  • 如果需要
    linear,请从设计中删除无效参数
    布局

  • 注意::如果仍然看到错误,请始终清理并生成项目

    以下不是
    LinearLayout
    的属性,它们属于
    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:layout_alignLeft="@+id/edit_message"
    
    android:layout_below="@+id/edit_message"
    
    
    android:layout_alignBottom="@+id/editText1"
    
    
    android:layout_alignParentRight="true"
    
    将主布局更改为
    ReativeLayout

    <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:layout_alignLeft="@+id/edit_message"
    
    android:layout_below="@+id/edit_message"
    
    
    android:layout_alignBottom="@+id/editText1"
    
    
    android:layout_alignParentRight="true"
    
    请通过并

    编辑

    替换

    <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>
    
    
    

    
    
    您的第一个
    编辑文本
    在最后结束,即在
    按钮
    之后。它应该像上面那样关闭

    
    
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
        <LinearLayout
            android:id="@+id/Leadlayout4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginBottom="8dp"
            android:orientation="horizontal"
            android:padding="10dp"
            android:weightSum="1">
    
            <Button
                style="@style/Widget.MaterialComponents.Button"
                android:id="@+id/Leadbutton1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_marginStart="5dp"
                android:layout_marginLeft="10dp"
                android:layout_marginEnd="10dp"
                android:layout_marginRight="10dp"
                android:layout_weight="0.5"
                android:gravity="center"
                android:onClick="saveButton"
                android:text="SAVE"
                android:textColor="@color/colorwhite"
                android:textSize="16sp"
                android:textStyle="bold" />
    
            <Button
                style="@style/Widget.MaterialComponents.Button.TextButton"
                android:id="@+id/Leadbutton2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="10dp"
                android:layout_marginEnd="10dp"
                android:layout_marginRight="10dp"
                android:layout_weight="0.5"
                android:background="@drawable/oval"
                android:gravity="center"
                android:onClick="clearButton"
                android:text="CLEAR"
                android:textColor="@color/colorblue"
                android:textSize="16sp"
                android:textStyle="bold" />
    
        </LinearLayout>
    </RelativeLayout>
    

    我以前在相对布局中使用过它,它也有相同的错误,这就是为什么我将它更改为线性布局,我认为这可以解决问题,但它没有。@kharmcatty它在我的eclipse上运行良好,请尝试清除并删除它build@KharlMccatty检查我的答案,你的第一篇文章有问题。你没有正确地关闭它。我以前在相对布局中有它,它有相同的错误,这就是为什么我把它改成线性布局,我认为可以解决问题,但它没有我以前在相对布局中有它,它有相同的错误,这就是为什么我把它改成线性布局,我认为可以解决问题,但它没有