1

我正在尝试构建一个应用程序,其中屏幕左侧有一个图像,右侧有一个写评论的地方(动态分配文本视图)。我在尝试将 Linearlayout 放置在 Relativelayout 中时遇到了错误。

以下是我的 xml 文件代码(减去几个按钮):

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

    <com.example.blueprintproj.PaintView
        android:id="@+id/paintView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/loadButton"
        android:background="@drawable/bp2" />

    <Linearlayout
        android:id="@+id/linearLayout"
        android:layout_width="120dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true" >

        <EditText 
    android:id="@+id/editText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
        />
        <Button 
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add+"
   />    
   </Linearlayout>

以下是我尝试运行时收到的错误消息:

07-10 02:35:50.207: E/AndroidRuntime(786): FATAL EXCEPTION: main
07-10 02:35:50.207: E/AndroidRuntime(786): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.blueprintproj/com.example.blueprintproj.MainActivity}: android.view.InflateException: Binary XML file line #80: Error inflating class Linearlayout
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.os.Looper.loop(Looper.java:137)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.app.ActivityThread.main(ActivityThread.java:5041)
07-10 02:35:50.207: E/AndroidRuntime(786):  at java.lang.reflect.Method.invokeNative(Native Method)
07-10 02:35:50.207: E/AndroidRuntime(786):  at java.lang.reflect.Method.invoke(Method.java:511)
07-10 02:35:50.207: E/AndroidRuntime(786):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-10 02:35:50.207: E/AndroidRuntime(786):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-10 02:35:50.207: E/AndroidRuntime(786):  at dalvik.system.NativeStart.main(Native Method)
07-10 02:35:50.207: E/AndroidRuntime(786): Caused by: android.view.InflateException: Binary XML file line #80: Error inflating class Linearlayout
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-10 02:35:50.207: E/AndroidRuntime(786):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.app.Activity.setContentView(Activity.java:1881)
07-10 02:35:50.207: E/AndroidRuntime(786):  at com.example.blueprintproj.MainActivity.onCreate(MainActivity.java:42)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.app.Activity.performCreate(Activity.java:5104)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-10 02:35:50.207: E/AndroidRuntime(786):  ... 11 more
07-10 02:35:50.207: E/AndroidRuntime(786): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.Linearlayout" on path: /data/app/com.example.blueprintproj-1.apk
07-10 02:35:50.207: E/AndroidRuntime(786):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
07-10 02:35:50.207: E/AndroidRuntime(786):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-10 02:35:50.207: E/AndroidRuntime(786):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.view.LayoutInflater.createView(LayoutInflater.java:552)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:643)
07-10 02:35:50.207: E/AndroidRuntime(786):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
07-10 02:35:50.207: E/AndroidRuntime(786):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)

请让我知道我做错了什么,或者如果您需要指出问题的任何其他信息!

太感谢了!

4

2 回答 2

5

拼写错误..使用LinearLayout而不是Linearlayout

于 2013-07-10T02:54:41.640 回答
0

试试这个,只保留一个 LinearLayout 并将方向更改为“水平”,而不是添加两个 LinearLayout 并更改宽度并添加权重,每个如下:

android:layout_width="0dp"
android:layout_weight="1"

请记住:您可以使用 android:layout_weight 更改 LinearLayout 将填充屏幕的空间量。

如果您放入weight = "1"一个 LinearLayout 而在另一个上放入weight = "1",则总和将为 2,因此第一个将填充屏幕的 1/2,另一个将填充 1/2,但如果您将第二个更改为“2”,总和为 3,因此第一个将占据屏幕的 1/3,第二个将占据屏幕的 2/3。

android:layout_ width = "0dp"出于性能原因设置,因为android:layout_wieght将设置大小值,因此您不需要向宽度添加另一个值

第二个布局将适合左侧的内容,第三个适合右侧的内容。希望能帮助到你

于 2013-07-10T03:45:37.257 回答