2014-04-02 284 views
-1

目前我正在研究有关android和gcm的论文。Android布局 - 创建聊天布局

我试图创建此布局的Android

enter image description here

,但我的项目不断粉碎。

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

post'LogCat' error。 –

+0

好的。只是一秒钟.. – user3487657

回答

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

请添加布局:heigth和布局:宽度参数在的EditText和也按钮图。 所以我希望它对你有用。

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

1

您必须具有android:layout_widthandroid:layout_height属性添加到每个XML 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" />