I'm trying to fix this so badly but I couldn't find where I've gone wrong.
The message:
Element type "LinearLayout" must be followed by either attribute specifications, ">" or "/>".
Why do I get this? Any ideas?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:weightSum="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
**<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_weight="70"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#0000FF"
android:padding="20dp"
android:paddingBottom="10dp"
android:gravity="center_horizontal">
</LinearLayout>
</LinearLayout>
It's a pretty self-explanatory error message.
You didn't close your LinearLayout tag. Add a > after android:orientation="vertical".
You missed a ">" at the end:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:weightSum="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
Your first LinearLayout tag isn't closed. Add a > to the end of it, like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:weightSum="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
^
Error clearly states that you missed the closing tag. Every Layout and its attribute needs to have their own opening and closing tag. Add
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_weight="70"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
or
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_weight="70"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
Related
I'm having a trouble using the <include> element in my layout files. The exact error is:
[databinding] {"msg":"\u003cinclude id\u003d\u0027#+id/displayArea\u0027\u003e conflicts with an ID used by a view in this layout","file":"badlayout/res/layout-land/main.xml","pos":[{"line0":10,"col0":2,"line1":20,"col1":16}]}
[databinding] {"msg":"\u003cinclude id\u003d\u0027#+id/displayArea\u0027\u003e conflicts with an ID used by a view in this layout","file":"badlayout/res/layout-port/main.xml","pos":[{"line0":10,"col0":2,"line1":10,"col1":67}]}
The problem happens when I set android:id in an <include> element in layout-port/main.xml:
<include android:id="#+id/displayArea" layout="#layout/display" />
while using the same ID directly in layout-land/main.xml:
<LinearLayout android:id="#+id/displayArea"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
...
</LinearLayout>
Experimenting shows I can't mix-n-match these. I can either specify android:id in the <include> tags, or in ordinary views, but not both.
Can anybody explain exactly what this message means, and what the rules are?
This is all complicated by the fact that you also can't set android:id at the top level of a layout file without running into different problems.
This is an older app. These layout files never gave me any trouble in Eclipse; I only started getting the errors after moving to Android Studio.
For completeness, the complete xml files are shown here:
layout-land/main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:id="#+id/displayArea"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false">
<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
layout-port/main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<include android:id="#+id/displayArea" layout="#layout/display" />
</LinearLayout>
layout/display.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<TextView android:id="#+id/StatusLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
I have a LinearLayout that has a lot of TextViews programatically put in. By a lot, I mean it extends beyond the bottom of my screen. I want to use a ScrollView to allow the user to scroll beyond the screen and see the rest of the TextViews. This is my activity_main.xml currently:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/ll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="61dp"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
Any help will be greatly appreciated! Thanks!
Try changing android:layout_width="wrap_content" to android:layout_width="match_parent"
<LinearLayout
android:id="#+id/ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="61dp"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
Change your code as below !
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/ll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="61dp"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
NOTE: To see if it is scrolling or not try placing some views inside linearLayout like buttons otherwise you won't notice the screen scrolling
Also You Can Do Like This.It Works Well.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollData"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical" >
<LinearLayout
android:id="#+id/linearWhere"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="vertical"
android:padding="5dp">
</LinearLayout>
</ScrollView>
To prevent multiple GetView calling I have set the height of ListView to fill_parent.
How to show other views than the ListView itself?
The following layout is inflated in a ViewPager:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="15dp" >
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>
where the included layout is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="20dp" >
<ScrollView
android:id="#+id/prontuariohome_scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none" >
.
.
.
.
</ScrollView>
</LinearLayout>
EDIT: This solution won't work for view higher than a button
I don't understand what you want to achieve, but if you NEED to have the height as fill_parent for some reason and can't be any other value, you can put the ListView with inside a LinearLayout with the height="0dp" and weight="1". So would be something like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="15dp" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>
Try to use following code
android:layout_height="0dp"
android:layout_weight="1"
in ListView tag
With android:layout_height="0dip" the view will take the rest of the free place
You said this solution is wont work:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/lv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white" android:layout_above="#+id/bt"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bt" android:layout_alignParentBottom="true"/>
just add it a android:layout_above="#+id/bt" to listview.
I'm sorry for being not clear.
Here is the link of the (probably) main thread asked here in Sof about the issue I was talking about.
After some tries I'm happy to give you the solution of my problem.
Giving another layout above the ListView lets the LV cuts the space not filled by the ListView itself
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="15dp" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>
error: Error parsing XML: junk after document element
I'm doing a VERY BASIC CODE JUST FROM NOTHING TO GET BETTER.
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical">
<textview
android:layout_width="1dp"
android:layout_weight="0dp"
android:layout_height="175dp"
android:text="#string/welcome_app"
android:text="#string/action_settings" ></textview>
</LinearLayout>
You are not allowed to have spaces at the end of the TextView tag.
Remove the " " at the end of the tag.
Replace <textview> with <TextView>
This should work:
<TextView
android:layout_width="1dp"
android:layout_height="175dp"
android:text="#string/action_settings"/>
// I Modify your code now try it.
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical" >
<TextView
android:layout_width="1dp"
android:layout_height="175dp"
android:text="#string/welcome_app" >
</TextView>
</LinearLayout>
The tags are case-sensitive, so use:
<Textview
android:layout_width="1dp"
android:layout_weight="0dp"
android:layout_height="175dp"
android:text="#string/welcome_app"
android:text="#string/action_settings" >
</Textview>
I can't understand why the following code places my TextView in the top left corner of my screen. Based on my understanding of layout_gravity, it seems that it should place my TextView at the bottom of my screen instead.
Can anyone please shed some light on this for me? This Linear Layout, despite seeming very simplistic, has caused me numerous headaches. How can something that seems so simple, be such a royal pain to grasp?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FF0000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello"
android:layout_gravity="bottom"
android:background="#FFF"
/>
</LinearLayout>
A LinearLayout set to vertical orientation will ignore all layout_gravity parameters that refers to vertical alignment. So for example "bottom" wont work but "center-horizontal" will work. (The vertical alignment is always done so that each view in the layout i placed under the other views in the layout.)
A relative layout might be the way to go or maybe you can use this code that probably is pretty close to what you want.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FF0000"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello"
android:gravity="bottom"
android:layout_weight="1.0"
android:background="#FFF" />
</LinearLayout>
Edit This blog explains things further.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF0000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello"
android:layout_alignParentBottom="true"
android:background="#FFF"
/>
</RelativeLayout>
you can use relative layout were you can align bottom easily
If that is the simplicity of your layout, you shouldn't wrap it in a LinearLayout at all.
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#FFF"
android:text="HELLO HELLO" />
If you need to wrap it though, remove the vertical orientation:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF0000" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#FFF"
android:text="HELLO HELLO" />
</LinearLayout>
I think this code do what you want:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom"
android:background="#FF0000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello"
android:background="#FFF"
/>
</LinearLayout>
And if you want the textview on center, you can use:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom"
android:background="#FF0000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello"
android:layout_gravity="center"
android:background="#FFF"
/>
</LinearLayout>
Hope this help you.