Reputation: 25
I'm trying to build an application where the left-side of the screen has an image and the right-side has a place to write comments (dynamically allocating textview). I ran into an error while trying to place Linearlayout within Relativelayout.
Following is my xml file code (minus few buttons):
<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>
Following is the error message I get when trying to run:
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)
Please let me know what I did wrong or if there is any other information you need to point out the issue!
Thank you so much!
Upvotes: 1
Views: 2313
Reputation: 1433
Try this, keep only one LinearLayout and change the orientation to "horizontal", than add two LinearLayout and change the width and add weight, for each one as the following:
android:layout_width="0dp"
android:layout_weight="1"
Remember: you can change how much space your LinearLayout will fill the screen using the android:layout_weight.
If you put weight = "1"
in one LinearLayout and on the other you put weight = "1"
, the sum will be 2, so the first one will fill 1/2 of the screen and the other 1/2, but if you change the second one to "2", the sum will be 3, so the first will fill 1/3 and the second, 2/3 of the screen.
You set android:layout_ width = "0dp"
for performance reasons since the android:layout_wieght
will set a size value, so you don't need to add another value to the width
The second Layout will fit the contents on the left and the third on the right. Hope it helps
Upvotes: 0