目前我正在撰写关于android和gcm的论文。
我正在尝试在android
中创建此布局
但我的项目一直在破碎。
<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=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#888888" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:layout_width="wrap_content"
android:inputType="textMultiLine" />
<Button android:text="@string/send" />
</LinearLayout>
</RelativeLayout>
错误记录
FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gcmchatting/com.example.gcmchatting.MainActivity}: java.lang.RuntimeException: Binary XML file line #21: You must supply a layout_height attribute.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.RuntimeException: Binary XML file line #21: You must supply a layout_height attribute.
at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:491)
at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:5457)
at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:5592)
at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1809)
at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1721)
at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:58)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:748)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
at android.app.Activity.setContentView(Activity.java:1867)
at com.example.gcmchatting.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) ... 11 more
答案 0 :(得分:3)
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/send" />
请在edittext和按钮视图中添加layout:heigth和layout:width参数。 所以我希望它对你有用。
答案 1 :(得分:1)
您必须向每个XML android:layout_width
添加android:layout_height
和View
属性。在您的XML中,您没有将高度属性添加到EditText
,高度和宽度都添加到Button
。所以,按如下方式添加它们......
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/send" />
答案 2 :(得分:0)
<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"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_above="@+id/bottom"
android:background="#888888" >
</LinearLayout>
<LinearLayout
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="2dp"
android:background="@drawable/border"
android:orientation="horizontal" >
<EditText
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_weight="0.7"
android:padding="10dp"
android:background="@drawable/border"
android:inputType="textMultiLine" />
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="Send" />
</LinearLayout>
和border.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#ffffff" />
<stroke
android:width="1dip"
android:color="#26000000" />