Unable to add LinearLayout as a first child in Umano's AndroidSlidingUpPanel - android

In AndroidSlidingUpPanel, Usage says..
To use the layout, simply include com.sothree.slidinguppaneldemo.SlidingUpPanelLayout as the Root element in your activity Layout. Make sure that it has two children. The first child is your main layout. The second child is your layout for the sliding up panel. Both children should have width and height set to match_parent. The following code is the sample code included in library.
<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"
tools:context=".DemoActivity" >
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Main Content"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eee"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="34dp"
android:gravity="center|bottom"
android:text="The Awesome Sliding Up Panel"
android:textSize="16sp" />
<TextView
android:id="#+id/brought_by"
android:layout_width="match_parent"
android:layout_height="34dp"
android:autoLink="web"
android:gravity="center|top"
android:text="Brought to you by http://umanoapp.com"
android:textSize="14sp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="fitStart"
android:src="#drawable/graphic" >
</ImageView>
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
The result of above xml layout is
I replaced the first child layout TextView(Main Content) with LinearLayout(any layouts) and it gives NullPointerException in Graphical Layout.

Close your layout by adding:
</RelativeLayout>
after
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

Please check the usage of the Umano library for your app. Here it is clear written that there should be exact two layout as child in the slidingUpPanel view. You can take it as any layout.
I have already try same thing with the RelativeLayout and LinearLayout and it works like charm.
Please let me know if your issue not resolved by this.
Enjoy Coding... :)

Related

when i created scroll view like this it's not working why...?

I created scroll view like this but its not working why i don't know please help me.when i did like this i'm getting error like this:Exception raised during rendering: Scroll View can host only one direct child.please help me how can i solve this problem .
enter code here
<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"
tools:context="com.example.jeshtamsru.tntrains.DashboarsActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="wrap_content"
android:width="300sp"
android:gravity="center"
android:layout_height="wrap_content"
android:text="chennai to coimbatore"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="wrap_content"
android:width="300sp"
android:gravity="center"
android:layout_height="wrap_content"
android:text="chennai to coimbatore"/>
</RelativeLayout>
</ScrollView>
If you are using Scroll view then it allows only one direct children. And as per how it works, it scrolls the child which is getting more space than available.
In your scenario Relative layout is not taking too much space to support scroll. And their are some basic errors in your layout also, like never give a button width in sp.
<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"
tools:context="com.example.jeshtamsru.tntrains.DashboarsActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="wrap_content"
android:width="300dp"
android:gravity="center"
android:layout_height="wrap_content"
android:text="chennai to coimbatore"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="wrap_content"
android:width="300sp"
android:gravity="center"
android:layout_height="wrap_content"
android:text="chennai to coimbatore"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Hope it will help :)
Scroll View can host only one direct child error itself says everything.
You have taken 2 RelativeLayout inside ScrollView, it must have atmost one child.
A ScrollView is a FrameLayout, meaning you should place one child in
it containing the entire contents to scroll
reference
Scroll View can host only one direct child
Wrap your layouts inside your scrollview inside a relative or linear layout.
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
... (stuff you had inside your ScrollView)
</RelativeLayout>
</ScrollView>

My scroll view doesn't scroll

I have a xml view like this, and as you see I have scroll view in it, but scroll view doesn't scroll and just match screen size, and I'm not able to see data under the screen.
This is my code:
CODE HAS BEEN UPDATED
<ScrollView
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:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/aboveRelative"
android:background="#color/darkOrange">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/category_text"
android:textSize="23sp"
android:textColor="#color/white"
android:text="Category"
android:paddingLeft="10sp" />
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="200dp"
android:verticalSpacing="0dp"
android:horizontalSpacing="10dp"
android:numColumns="2"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/gray"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/topVoices"
android:textSize="23sp"
android:text="#string/topVoices"
android:paddingLeft="10sp" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/trendlist"
android:elevation="2dp"
android:background="#color/white"
android:layout_margin="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/moreTrend"
android:layout_gravity="right"
android:textSize="23sp"
android:text="More"
android:paddingLeft="10sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/newVoices"
android:textSize="23sp"
android:text="#string/newVoices"
android:paddingLeft="10sp" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/soundlist"
android:background="#color/white"
android:layout_below="#+id/newVoices"
android:elevation="5dp"
android:layout_margin="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/soundlist"
android:id="#+id/moreNew"
android:layout_gravity="right"
android:textSize="23sp"
android:text="#string/more"/>
<LinearLayout
android:id="#+id/yoursongs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:background="#color/white"
android:padding="10dp">
</LinearLayout>
</LinearLayout>
</LinearLayout>
I'm sure that there are some data under the screen but scroll view doesn't let me scroll it and see them.
Scrollview layout can only have ONE child layout. You still have TWO linear layout children in the XML you posted.
This is explained in the first paragraph of the Android developer documentation for ScrollView:
http://developer.android.com/reference/android/widget/ScrollView.html
Your layout is wrong. Here's what you gotta do:
Change your ScrollView layout_height attribute to match_parent.
The ScrollView will take the whole screen and make itself scrollable, that's why you need it as match_parent. The scrolling happens inside the View.
Put everything inside the ScrollView in a Linear or RelativeLayout. (see below)
The ScrollView extends FrameLayout, so it can only have a single child view.
IMPORTANT: this layout must have the attribute layout_height set to wrap_content, otherwise the ScrollView won't have anything larger than itself to scroll.
I'd also remove the root layout from the XML and leave the ScrollView as root.
Simply because it's pointless and it requires extra work from the LayoutInflater.
EDIT: your layout is also way more complex that it needs to be.
It lead me to believe you did not have a single child inside the ScrollView (which you do).
Still, item #1 should fix your problem.
Finally, I found answer. The problem was from fillviewport in scroll view. if you remove fillviewport and set fix size for listview, you can scroll.

android linearlayout has no known child tags Error

I have following xml in my android app:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/msngr"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/logo" />
</LinearLayout>
</ScrollView>
Upto this code is fine, but i am not able to add any other components like TextView,Edittext in this.
I am not getting any autosuggest for it and viewing in redline that:
<linearlayout> has no known child tags
How can i components in linear layout?
plz help me.
This is because in ScrollView you can only add one Child View... It can't add any other view in it... Because ScrollView host only one child view...
also remove space from Linear Layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/logo"/>
</LinearLayout>
because space not allowed......
and if you want to add child view then add it to only LInear Layout

linear layout doesn't fit to screen size

Why the linear layout inside a scroll view doesn't fit to the screen size?
I was trying to make some changes with the "Layout_Height" but doesn't succeeded.
This is my XML code:
Thanks for help!
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollViewPhysicalExam"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
style="#style/HeaderText"
android:orientation="vertical" >
<!-- ++++++++++++++++++ Row18 ++++++++++++++++++ -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/btnBack"
android:text="#string/Back"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.00"
android:textSize="15dip" />
<Button
android:id="#+id/btnSave"
android:text="Save"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.00"
android:textSize="15dip" />
</LinearLayout>
<!-- +++++++++++++++++++++++++++++++++++++++++++ -->
</LinearLayout>
</LinearLayout>
</ScrollView>
I can't comment, so I'll try to answer:
Did you try to set android:fillViewport="true" in your ScrollView?
1) Why would you nest a LinearLayoutinside a LinearLayout inside another LinearLayout?? I can only assume this is just an excerpt of your xml-file, otherwise this doesn't make any sense.
2) What exactly is the problem you encounter? The LinearLayout is too long so that it leaves the visible screen at the bottom?
If so, this is due to the ScrollView as the parent element. A ScrollView will fill the screen by setting android:layout_height="match_parent". A ScrollView itself gives an unbounded space of height to its children, so setting android:layout_height="match_parent" inside the child view (LinearLayout) will make it take infinite space as well. You should set it to android:layout_height="wrap_content" and see if that works out for you!

Help with stacked layout

I am trying to make a stacked layout with a fixed header, expandable body and fixed footer. I am very close however the body section with the webview displays behind the footer rather than between the header and footer. TIA
Jim
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/header"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/header"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Karen" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_below="#id/header"
>
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
/>
<LinearLayout
android:id="#+id/footer"
android:layout_width='fill_parent'
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:background="#000000"
>
<EditText
android:id="#+id/inputText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Is on the bottom"
android:layout_weight="1"
android:textSize="15sp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textSize="15sp"
android:text="send" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
I am trying to make a stacked layout with a fixed header, expandable body and fixed footer
Step #1: Make the root layout a RelativeLayout.
Step #2: Add the header as a child of the RelativeLayout, anchored to the top (android:layout_alignParentTop="true")
Step #3: Add the footer as a child of the RelativeLayout, anchored to the bottom (android:layout_alignParentBottom="true")
Step #4: Add the body as a child of the RelativeLayout, anchored to the header (android:layout_below="...") and footer (android:layout_above="...")
SOLVED.
I needed to reorder the items in the .xml file by putting the center item (webview) at the bottom and add android:layout_above="#id/footer".
I learned that when android processes id's they must be defined prior to using then in directives such as android:layout_above="#id/footer".
This is much like javascript processing on page load, the functions have to be defined prior to execution.
BTW thanks to everyone at StackOverFlow, you make this an invaluable resource to developers.

Categories

Resources