嘿,我是 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_alignLeft
、android: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/