Error in displaying nested LinearLayout - android

I am using nested linearlayout in my xml file.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:text="left"
android:layout_weight="1"
android:layout_gravity="left"
android:id="#+id/previous"></Button>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:id="#+id/date"
android:textColor="#505050"
/>
<Button android:text="right"
android:layout_weight="1"
android:layout_gravity="right"
android:id="#+id/next"></Button>
</LinearLayout>
.........
........
</LinearLayout>
My application doesnt start , i get an error message saying the process stopped unexpectedly. Though it works without the inner Linearlayout.
Any ideas why?
Thanks

You should definitely post the stack trace when you have exceptions thrown and you want help, but in this case you seem to be missing the layout_width and layout_height attributes for your buttons.

Related

is not a sibling in the same 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.

unfortunately app stop working: Failed to find style 'mapViewStyle' in current theme

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

how to design great design's for a Android Activity

What I'm Trying to do
At the moment I'm creating a design for my Activity, which has different kind of "boxes" in it. Every of those "boxes", has diffrent informations in it. I created the design by hand on a piece of paper, but I won't get the idea down in my .xml!!
Question
On the bottom of this post you'll find a copyed "box" which I'd like to create for my app. Please help me to realize this, because I really don't get how to do this in my XML! I'm working with Android 4.0 (ICS).
Something like this should work:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/box_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Box Title" />
<LinearLayout
android:id="#+id/box_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/box_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/box_content_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hans Max" />
<TextView
android:id="#+id/box_content_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Maxiburger 12" />
<TextView
android:id="#+id/box_content_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8002, Muster" />
</LinearLayout>
<ImageButton
android:id="#+id/box_button"
android:layout_weight="5"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</LinearLayout>
I give you the pseudo layout:
<RelativeLayout>
<TextView
full width
id:infobox/>
<Button
layoutParentRight
below infobox/>
<TextView
layout_below infobox
toLeftOf button/>
// repeat the textView above and always below the previous one
</RelativeLayout>
With LinearLayouts:
<LinearLayout>
<TextView infobox/>
<LinearLayout>
<LinearLayout>
<TextView />
<TextView />
<TextView />
</LinearLayout>
<Button/>
</LinearLayout>
</LinearLayout>
As you see it is much more complex and bloated. As I always get confused by horizontal/vertical orientation I leave this to you to find out :)
Just experiment and if you can't get it to work, update your answer with the layout you tried.

Android SlidingDrawer

I'm trying to put a Sliding Drawer to my activity using this tutorial. My app is for Android 2.1-update1 (API 7). When i create a xml layout like this:
<?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">
<SlidingDrawer
android:id="#+id/slidingDrawer"
android:handle="#+id/drawerHandle"
android:content="#+id/contentLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout android:id="#+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center">
<EditText android:text="" android:id="#+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="100px"/>
<Spinner android:id="#+id/spinner1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:prompt="#string/strFilter" />
<Button android:text="Filtriraj" android:id="#+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
</SlidingDrawer>
<ScrollView android:layout_height="fill_parent" android:layout_width="fill_parent">
<TableLayout android:layout_width="fill_parent" android:id="#+id/tableLayout1" android:layout_height="fill_parent" android:orientation="horizontal">
<TableRow android:id="#+id/tableRow1" android:layout_height="wrap_content" android:baselineAligned="true" android:layout_gravity="center_horizontal" android:clipChildren="true" android:gravity="center_horizontal" android:layout_width="fill_parent" android:layout_margin="3dip">
<TextView android:clickable="true" android:layout_height="wrap_content" android:text="#string/lblOd" android:id="#+id/textView1" android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:layout_marginRight="5dip"></TextView>
<TextView android:clickable="true" android:layout_height="wrap_content" android:id="#+id/textView2" android:text="#string/lblDatum" android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:drawableLeft="#drawable/arrowdown"></TextView>
<TextView android:clickable="true" android:layout_height="wrap_content" android:id="#+id/textView3" android:text="#string/lblTekst" android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:layout_marginLeft="3dip"></TextView>
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
I got an exception when switch to "design view" - Graphical Layout. Error is
ClassCastException: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log
The following classes could not be found: - SlidingDrawer
What's wrong with my code?
Switch design view to Android 3.0 then it works, somekind of a bug in ADT. If you run it in emulator, then code works.
Unfortunately, you'll be designing/laying out things for 3.0, when your app will be running on MILLIONS of 2.x devices instead.
Fully qualifying the SlidingDrawer class name (android.widget.SlidingDrawer) resolved this issue for me. This only seems to work for 2.1-update1 and above however.
Also, be sure that you set the drawer handle to a valid child of the drawer.

Layout problems. Android

I have some behaviour of my layout. I give two of them, very similar to each other. Only one difference is the width attribute of the textviews.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:isScrollContainer="true"
android:gravity="center"
android:background="#color/black">
<LinearLayout
android:id="#+id/tabs"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#color/black"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Einstellungen"
android:drawableTop="#drawable/selector_settings"
android:id="#+id/main_menu_button_connection"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="10px">
</TextView>
...
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Suche"
android:drawableTop="#drawable/selector_search"
android:id="#+id/main_menu_button_connection"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="10px">
</TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
If layout_width is set to wrap content, I get following layout results:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:isScrollContainer="true"
android:gravity="center"
android:background="#color/black">
<LinearLayout
android:id="#+id/tabs"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#color/black"
android:layout_weight="1">
<TextView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="Einstellungen"
android:drawableTop="#drawable/selector_settings"
android:id="#+id/main_menu_button_connection"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="10px">
</TextView>
...
<TextView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="Suche"
android:drawableTop="#drawable/selector_search"
android:id="#+id/main_menu_button_connection"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="10px">
</TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
If layout_width is set to a value instead (here 70dp), my layout looks so, I want it to have:
Can anybody explain me, why?!
Is there some solution avoiding to set a constant width and still having layout result like at the second picture?!
Thank you in advance
You probably want to give each TextView an equal layout weight such as android:layout_weight="1" and a width of fill_parent. Also, don't give a weight for the tabs linear layout. Also, while I don't really know what's going on later in the layout file, having three nested LinearLayouts seems like it might be wasteful. Maybe you can get rid of one of them?
I recommend starting over and using the eclipse designer view or use droiddraw to create the layout, especially since there are recent improvements to the layout editor.

Categories

Resources