I have this XML file:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:text="Disable Filter" android:background="#drawable/buttons" style="#style/ButtonText" android:layout_weight="25" />
<ImageView android:id="#+id/imageFilter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="75" />
<HorizontalScrollView android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:id="#+id/horizontal" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
As soon as I add android:id="#+id/btnFilterPreview" to the Button my app stops working. Why is that?
In Netbeans to solve the issue, Right click on the Project and and chose: Clean and Build
Clean Build your project so that all id is regenerate and application will find reference of new ids.
This is a Same code of you . Running Perfect Without any changes.
I had just Clean & Re-Build Project Nothing else .
Try it.
<Button
android:id="#+id/btnFilterPreview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="25"
android:background="#drawable/ic_action_search"
android:text="Disable Filter" />
<ImageView
android:id="#+id/imageFilter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="75" />
<LinearLayout
android:id="#+id/horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="25"
android:orientation="horizontal" >
</LinearLayout>
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</HorizontalScrollView>
It may also be caused Android automatically adds android.R in its header file remove it
and then Build Project Again
Besides Clean and Build, make sure you do not have duplicate IDs.
Say you have another ImageView with the same ID, it could crash when some code like
(Button)findViewById(R.id.btnFilterPreview)
is executed.
Related
I'm trying to show a button over a fullscreen image. I tried to use RelativeLayout as shown in this question but I cannot see the Button.
Can someone tell me why this code isn't working?
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pitchImageView"
android:src="#drawable/gaa_pitch"
android:scaleType="centerCrop"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/start"
android:id="#+id/stopwatchButton"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
Apologies if this qualifies as a duplicate question.
EDIT:
Screenshots of the activity.
Android design tab
Emulator at runtime
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pitchImageView"
android:src="#drawable/gaa_pitch"
android:scaleType="centerCrop"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/start"
android:id="#+id/stopwatchButton"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
My friend you can use FrameLayout alternatively ,and checkout this site : Android Frame Layout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pitchImageView"
android:src="#drawable/desert_road"
android:scaleType="centerCrop"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:src="#drawable/ic_clear_white_24dp"
android:id="#+id/stopwatchButton"
android:layout_gravity="center" />
</FrameLayout>
The Result :
This is a common "problem".
You can try a couple of things:
Invalidate caches and restart Android Studio, or just restart without invalidating
Try the Run -> Clean and rerun option
Or the Build -> Clean project or Build -> Rebuild Project options
When you are done, run the project again.
Well I got it working, I can't exactly explain what fixed it but these are the steps I took:
Utilised a content and activity split. (to get an example of this create a basic activity in android studio).
I deleted other versions of the layout files in the version compatible folders (such as "layout-v24").
I also used "Clean" and "Rebuild" project options whenever I made a change to my code.
activity xml file:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true">
<include layout="#layout/content_record_game"/>
</android.support.design.widget.CoordinatorLayout>
This is my content.xml file
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pitchImageView"
android:contentDescription="#string/image_of_a_gaa_pitch"
android:src="#drawable/gaa_pitch"
android:scaleType="centerCrop"
android:cropToPadding="false"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/start"
android:id="#+id/stopwatchButton"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Hello I am starting with Android developing. I am just modifying with ECLIPSE an open source example. I have only modified strings.xml and some .png files. In the Android simulator it works perfect but when I try to generate the signed apk file I receive two errors with similar description. This is one of them (the line is marking with *):
Description #+id/about_us_desc_webview is not a sibling in the same RelativeLayout cc3x_about_us.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#android:style/Theme.Black.NoTitleBar.Fullscreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey_background"
android:orientation="vertical" >
<include
android:id="#+id/cc3x_about_header_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/cc3x_headerlayout" />
<TextView
android:id="#+id/about_us_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/cc3x_about_header_view"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/about_title_label_top_margin"
android:text="#string/about_us_label"
android:textColor="#color/grey_text_color"
android:textSize="#dimen/extra_large_text_size"
android:textStyle="bold" />
<View
android:id="#+id/view1"
android:layout_width="fill_parent"
android:layout_height="#dimen/min_divider_height"
android:layout_below="#+id/about_us_textview"
android:layout_marginLeft="#dimen/about_title_label_side_margin"
android:layout_marginRight="#dimen/about_title_label_side_margin"
android:background="#drawable/about_page_divline" />
<WebView
android:id="#+id/about_us_desc_webview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/view1"
android:layout_marginLeft="#dimen/about_title_label_side_margin"
android:layout_marginRight="#dimen/about_title_label_side_margin"
android:layout_marginTop="#dimen/min_margin_cutoff" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/about_us_desc_webview" >
<TextView
android:id="#+id/about_screen_contact_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
* android:layout_below="#+id/about_us_desc_webview"
android:layout_centerHorizontal="true"
android:text="#string/contact_label"
android:textColor="#color/grey_text_color"
android:textSize="25dip"
android:textStyle="bold" />
<View
android:id="#+id/divider_bottom"
android:layout_width="match_parent"
android:layout_height="#dimen/min_divider_height"
android:layout_below="#+id/about_screen_contact_label"
android:layout_marginLeft="#dimen/about_title_label_side_margin"
android:layout_marginRight="#dimen/about_title_label_side_margin"
android:background="#drawable/about_page_divline" />
<TextView
android:id="#+id/about_xcube_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/divider_bottom"
android:layout_margin="#dimen/max_margin_size"
android:autoLink="web"
android:text="#string/xcube_url"
android:textColor="#color/blue_text_color"
android:textColorLink="#color/blue_text_color"
android:textSize="10dip" />
<TextView
android:id="#+id/about_xcube_contact_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/divider_bottom"
android:layout_margin="#dimen/max_margin_size"
android:autoLink="email"
android:text="#string/xcube_contact_email"
android:textSize="#dimen/small_text_height" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/about_xcube_link"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="#string/about_xcube_address"
android:textColor="#color/grey_text_color"
android:textSize="#dimen/small_text_height" />
</RelativeLayout>
</RelativeLayout>
Any help will be apreciated. Thank you very much!!
The line
android:layout_below="#+id/about_us_desc_webview"
in your TextView is redundant. Since the RelativeLayout already has that attribute, it is useless. You can just erase that line and nothing should change.
And the reason it generates error is that, you can apply features such as below, above.. etc with an element in the same layout. Here "about_us_desc_webview" is out of the RelativeLayout and you cannot position something inside a RelativeLayout with something outside a RelativeLayout.
android:layout_below
Positions the top edge of this view below the given anchor view ID .
When Arise
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:id="#+id/rl_rootHeader"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/rl_Header"
android:layout_below="#+id/rl_rootHeader" // Arise ,In here RelativeLayout is Parent .
>
//
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:fillViewport="true"
android:id="#+id/scrollRoot"
android:background="#color/colorWhite"
>
</ScrollView>
Right Way
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:id="#+id/rl_rootHeader"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/rl_Header"
>
//
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:fillViewport="true"
android:id="#+id/scrollRoot"
android:background="#color/colorWhite"
android:layout_below="#+id/rl_rootHeader" // Call Here .This section is Child
>
</ScrollView>
In my case, The problem was with Kotlin Version. I updated the the Kotlin version and the problem "is not a sibling in the same RelativeLayout" resolved
Just remove the lines which are causing error from layout
.xml file
Try refreshing the layout
Your layout will probably change. You can now reset it properly.
If you go to Properties Panel you will see layout:alignComponent has some alignment shown as "Not Found". Just clear it out. In the above example Properties window -> textview -> layout:alignComponent check all alignment values.
I saw so many answer of this question here but not one solve my problem. I am trying to make a tab layout I which there is text is text view in table layout and below table layout I want to add map. and I'm trying to do this but not get the result.
my error is
Failed to find style 'mapViewStylr' in current theme
after adding the MapView I got this error. and when I run the code on Nexus one and try to open the layout in which I added the MapView then the application Unfortunately stopped.
here is my layout code
<?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="wrap_content"
android:orientation="vertical"
android:background="#android:color/white"
>
<ScrollView
android:id="#+id/info_tab"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<RelativeLayout
android:id="#+id/venuinfolayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/white" >
<TableLayout
android:id="#+id/venuetable"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:fitsSystemWindows="true"
android:weightSum="2"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="#+id/venueaddress"
android:text="Address:"
android:textColor="#android:color/black"
android:padding="6dip"
android:textStyle="bold"
android:textSize="20dip" />
<TextView
android:id="#+id/venueaddress_details"
android:layout_height="wrap_content"
android:layout_width="180dip"
android:singleLine="false"
android:layout_toRightOf="#id/venueaddress"
android:textColor="#android:color/black"
android:text="text"
android:layout_marginLeft="10dip"
android:padding="6dip"
android:textSize="15dip"
/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="#+id/venuephone"
android:layout_below="#id/venueaddress"
android:text="Phone:"
android:textColor="#android:color/black"
android:padding="6dip"
android:textStyle="bold"
android:textSize="20dip" />
<TextView
android:id="#+id/venuephone_details"
android:layout_below="#id/venueaddress_details"
android:layout_toRightOf="#id/venuephone"
android:text="number"
android:textColor="#android:color/black"
android:layout_marginLeft="10dip"
android:padding="6dip"
android:textSize="15dip" />
</TableRow>
</TableLayout>
<com.google.android.maps.MapView
android:id="#+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/venuetable"
android:clickable="true"
android:apiKey="AIzaSyAvWazTUUQr88b_UqQvB4k5rPAtOhlxTFA" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
//try this it may help you
Add this into your manifest file
<uses-library android:name="com.google.android.maps" />
I had the same problem when I try to build a simple app, following the Android MapView tutorial.
The app showed this exception in AVD for the file file main.xml:
Failed to find style 'mapViewStyle' in current theme
At last I found that there is a mistake in file AndroidManifest.xml:
The element should be a child of the element, not immediately within .
Hope this was any help to you.
OR
look Here
In my project I have created a global header layout global_header.xml and I use it in all of my layout XML files by using <include layout="#layout/global_header.xml">.
I have used this method before, and I am currently using it in this project. My problem is that I have a layout with the following contents:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF" >
<include layout="#layout/global_header" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/global_header">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Contents of global_header.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/global_header"
android:layout_width="fill_parent"
android:layout_height="60sp"
android:layout_alignParentTop="true"
android:background="#FFDDDDDD" >
<ImageView
android:id="#+id/global_header_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5sp"
android:layout_marginTop="5sp"
android:adjustViewBounds="true"
android:src="#drawable/header" />
<View
android:layout_width="fill_parent"
android:layout_height="1sp"
android:layout_alignParentBottom="true"
android:background="#FF000000" />
</RelativeLayout>
And I am getting an error on android:layout_below="#global/header" saying that:
error: Error: No resource found that matches the given name (at 'layout_below' with value '#global/header').
I have used the include in other layouts in the project and it works without a problem, but for whatever reason, this layout file will not load the ID from the header where as all other layouts do.
The project will not build with this error even though I am sure that once running on the device it will find it not a problem, has anyone else had this problem? Is there solution/workaround?
Any and all help is greatly appreciated.
Try this, specify id for include layout and use
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF" >
<include layout="#layout/global_header" android:id="#+id/header"/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/header">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</RelativeLayout>
</ScrollView>
Hope both xml (main.xml & global_header.xml) is exist in your layout folder within resources.
kindly clean the project and restart your eclipse, it works.
Note# I checked your xmls I didn't got any error.
I know this is asked a lot but I got error parsing xml junk after document element problem and then after while of looking for the problem I got 10 r can not be defined errors i think it all resulted from the first error. But even when I remove the problem paragraph and click clean the error red x is still there on a blank area.The error started on the textview line at the bottom.
<?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="25dp" >
<EditText
android:id="#+id/etCommands"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Type a Command"
android:password="true" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >
<Button
android:id="#+id/bResults"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="20"
android:text="Try Command" />
<ToggleButton
android:id="#+id/tbPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="80"
android:checked="true"
android:paddingBottom="10dp"
android:text="ToggleButton" />
</LinearLayout>
<TextView
android:text="invalid"
android:id="#+id/tvResults"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" />
should be
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >
Notice no / at the end of the tag. The / at the end is xml for "close this tag right now please." As it stands, you have invalid xml with two open tags for LinearLayout but closing LinearLayout 3 times.
It's hard to know what is the problem when you don't provide the full xml file. You probably forgot to close one of your LinearLayout items.
edit:
simply delete the / character from your LinearLayout declaration:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >