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>
Related
I'm not sure that extendable list is the best solution for this but this is the only thing that came to my mind.
Here is my problem:
I want to create a list and when I click on an element one (or maybe there'll be multiple) element'll appear and push down the other elements that are below it. This is how the extendable list works, but here comes my problem I want that the child element are in front of the group elements and I have no idea how could I do it.
Here it is a picture maybe you can understand it better:
As Gavriel requested:
main:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context="com.example.lalala.listview.MainActivity">
<ExpandableListView
android:id="#+id/extd_list"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
</android.support.design.widget.CoordinatorLayout>
group:
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout 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="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
android:background="#000000">
<TextView
android:id="#+id/left_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_widthPercent="75%"
android:textSize="17dp"
android:textColor="#f9f93d" />
<TextView
android:id="#+id/right_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_widthPercent="25%"
android:layout_toRightOf="#+id/left_text"
android:textSize="17dp"
android:textColor="#f9f93d" />
</android.support.percent.PercentRelativeLayout>
expanded child:
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="55dip"
android:orientation="vertical" >
<TextView
android:id="#+id/extended_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="17dip"
android:paddingTop="20dp"
android:paddingBottom="20dp" />
</android.support.percent.PercentRelativeLayout>
What i did in a similar situation was to copy the ExpandableListView's layout xml into my project, and modify it according to my needs, and create MyExpandableListView extends ExpandableListView that uses my version of the layout and doesn't change anything else. I hope this helps.
I'm having a problem where I want each subchild of a view for a listview to have it's own custom selector. There are a few solutions already but none of them seem to work at all for me. Here's my xml for the listview and individual view. Does anyone know specifically what I need to do? Right now If I can get show_group_actions and action_calendar to have separate selectors working I'd be quite happy...
<?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="wrap_content"
android:descendantFocusability="afterDescendants"
android:orientation="vertical">
<LinearLayout
android:id="#+id/action_show_group_actions"
style="#style/AppTheme.NavigationDrawer.Row"
android:paddingRight="0dp"
>
<TextView
android:id="#+id/group_name"
style="#style/AppTheme.NavigationDrawer.Row.TextView"
android:text="#string/label_my_groups"
/>
<RelativeLayout
style="#style/AppTheme.NavigationDrawer.Group.OpenClose"
>
<me.magneto.groups.views.IconView
android:id="#+id/action_show_group_actions_arrow"
style="#style/AppTheme.NavigationDrawer.Group.OpenClose.Arrow"
android:text="#string/icon_chevron_down"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/action_calendar"
style="#style/AppTheme.NavigationDrawer.Group.Row"
>
<me.magneto.groups.views.IconView
style="#style/AppTheme.NavigationDrawer.Group.IconView"
android:text="#string/icon_calendar"
/>
<TextView
style="#style/AppTheme.NavigationDrawer.Row.TextView"
android:text="#string/label_calendar"/>
</LinearLayout>
</LinearLayout>
<ListView
android:id="#+id/navigation_drawer_list_view"
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:listSelector="#null"
android:background="#color/navigation_primary_background"
/>
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>
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>
I've got two layouts first and second, I want to insert second to first.
I want to insert second layout into layout that has id #+id/layout
when I press button Get Layout, it show the the second layout on the bottom of button
first layout
<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" >
<Button
android:id="#+id/btn_get_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Layout" />
<LinearLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
second layout
<?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:background="#drawable/card_base"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/img_cover"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
android:scaleType="fitXY"
android:src="#drawable/card_beauty" />
<ImageView
android:id="#+id/img_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="20dp"
android:scaleType="fitXY"
android:src="#drawable/sample_0" />
</RelativeLayout>
</LinearLayout>
if I understood you right you should use the following code within your first layout
<include
layout="#layout/second_layout"
android:id="#+id/includedLayout"
android:visibility="gone"
android:layout_below="#id/buttonId" />
and then in your button's action you just use
((RelativeLayout)findViewById(R.id.includedLayout)).setVisibility(View.VISIBLE);
LinearLayout placeHolder = (LinearLayout) findViewByid(R.id.layout);
getLayoutInflater().inflate(R.layout.second_layout, placeHolder);
Use include
Here is a somewhat fuller example. The square blue layout is inserted into the main layout using include.
activity_main.xml
This is the main layout. The custom layout is referenced using include. You can override any of the attributes here, too.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<!-- Here is the inserted layout -->
<include layout="#layout/my_layout"/>
</RelativeLayout>
my_layout.xml
This is the custom layout that will be inserted into the main layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="5dp"
android:text="My Layout"/>
</RelativeLayout>
You Should use this code snippet to add a Layout inside another one.
parentLayout=(LinearLayout)findViewById(R.id.parentLayout);
inflateView=View.inflate(this,R.layout.view_video,parentLayout);
Here the parentLayoutis the root View and R.layout.view_video is the layout that you need to insert.
Use LayoutInflator to inflate an external layout into existing layout. Checkout LayoutInflater on Android Dev Site for more information about it.