I have been trying to run this code but getting this error since last 1 week.
Please help!
I have already declared layout:width.
Tried with layout.width in sliding drawer and replacing dp wit dip but still got the same error.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<SlidingDrawer
android:id="#+id/drawer"
android:width="320dp"
android:height="440dp"
android:orientation="vertical"
android:content="#+id/content"
android:handle="#+id/handle">
<ImageView
android:id="#+id/handle"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="#drawable/ic_launcher"/>
<AnalogClock
android:id="#+id/content"
android:background="#D0A0A0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</SlidingDrawer>
</RelativeLayout>
Layout tags are mandatory tags I believe. You have not supplied layout_width and layout_height to your SlidingDrawer
android:layout_width="fill_parent"
android:layout_height="fill_parent"
Related
<TabHost
android:id="#+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
// --------------------------- Here I got warning -------------------------
<LinearLayout
android:id="#+id/chat_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="visible" >
// --------------------------------------------------------------------------
<ListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/white" >
</ListView>
<LinearLayout
android:id="#+id/text_entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="horizontal" >
<EditText
android:id="#+id/txt_inputText"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:hint="#string/enter_text"
android:inputType="text" />
<Button
android:id="#+id/btn_Send"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="#string/send" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" >
</TabWidget>
</LinearLayout>
</TabHost>
How to solve this warning ? I can't find any solution. Any help will be appreciated.
I am not sure what exactly you are trying to accomplish, but you can get rid of the warning by moving FrameLayout content to a separate file and add it back to your TabHost by using <include> tag.
A possible version could look something like this:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<include layout="#layout/tab_chat_list" />
</FrameLayout>
</LinearLayout>
</TabHost>
And tab_chat_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="#+id/chat_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="visible" >
<ListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/white" >
</ListView>
<LinearLayout
android:id="#+id/text_entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="horizontal" >
<EditText
android:id="#+id/txt_inputText"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:hint="#string/enter_text"
android:inputType="text" />
<Button
android:id="#+id/btn_Send"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="#string/send" />
</LinearLayout>
</LinearLayout>
</merge>
Hope this helps.
Update
I noticed that some people are suggesting to remove FrameLayout. Although, that could have solved the problem in other cases, TabHost needs TabWidget and FrameLayout to function correctly.
The warning you are getting is this one:
UselessParent
Summary: Checks whether a parent layout can be removed.
Priority: 2 / 10 Severity: Warning Category: Performance
A layout with children that has no siblings, is not a scrollview or a
root layout, and does not have a background, can be removed and have
its children moved directly into the parent for a flatter and more
efficient layout hierarchy.
It can be turned off in Lint.
Update: I missed that tabhost requires a framelayout to work. Disabling the warning or going with shoe rat's solution should still fix the problem. (ignore paragraph below)
Assuming you don't need the FrameLayout (i.e. to add stuff dynamically), you can try removing it and adjusting the LinearLayout accordingly:
<LinearLayout
ndroid:id="#+id/chat_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:visibility="visible" >
Take a look at the following layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llParent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rlInner"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some Text" />
</RelativeLayout>
</LinearLayout>
There is nothing wrong with it and any activity using this layout will run without a problem. But eclipse will give you a warning:
This RelativeLayout layout or its LinearLayout parent is useless
As you can see, I only need one of the two container layouts above. Adding the RelativeLayout with id="rlInner" does nothing to change the layout. When eclipse finds a scenario like this, it gives you an appropriate warning to indicate the redundancy.
In your scenario, you can lose the FrameLayout altogether without disturbing the layout. And this would fix the warning.
Add an ID to the parent linear layout.
It's useless because the parent linear layout doesn't have an id. It means it would be difficult or impossible to add stuff in code outside the linear layout where you got the error.
I am trying to use a SlidingDrawer which has a bottom to top structure.. I have placed 4 spinners inside the content of that sliding drawer.. And when i executes, the handle(which i have an image) is showing above the screen. I want that handle just above the content(ie just above the 4 spinners..)
here is my xml layouts...
main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<SlidingDrawer
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/drawer"
android:handle="#+id/MyHandle"
android:content="#+id/MyContent">
<LinearLayout
android:id="#+id/MyHandle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="vertical">
<ImageView
android:id="#+id/SlideIcon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/images"/>
</LinearLayout>
<FrameLayout
android:id="#+id/MyContent"
android:layout_width="fill_parent"
android:layout_height="200dip"
android:orientation="vertical">
<include
android:id="#+id/DrawerContent"
layout="#layout/spinnerlayout"
android:layout_height="wrap_content"/>
</FrameLayout>
</SlidingDrawer>
</FrameLayout>
and spinnerlayout.xml..
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:foregroundGravity="bottom"
android:layout_gravity="bottom"
android:background="#color/grey">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner_first"/>
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner_second"/>
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner_third"/>
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner_fourth"/>
</LinearLayout>
</FrameLayout>
And to make my question more clear, i have the screenshots..
I want to have that handle(arrow) just above that spinners..
Is it possible to place it?
The onMeasure() method of the SlidingDrawer class basically overrides the layout modes to fill_parent, this is why layout_height="wrap_content" is not working.
To get around this, you can extend SlidingDrawer with a re-implemented onMeasure() method that honors the layout_width and layout_height attributes. You can then use this custom class in your XML layout by replacing with .
Note that since the drawer will no longer be filling the parent layout, you will have to enclose it in a LinearLayout with the gravity attribute set to the edge where the drawer should be.
the Answer
your Question
My xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:visibility="invisible">
<ImageButton
android:id="#+id/video_playback_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<SeekBar
android:id="#+id/seekbar_video"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_below="#id/video_playback_pause" android:clickable=""/>
</RelativeLayout>
<VideoView
android:id="#+id/videoView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true" />
</RelativeLayout>
Now whe RelativeLayout and VideoView override.
the VideoView is show, and the RelativeLayout is hidden.
How to make the RelativeLayout on the top of VideoView?
Another problem is why the seekbar did not click?
I find that the priority of layout is decide by establish order?
But the problem of seekbar is still not resolve.
Try this...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" >
<ImageButton
android:id="#+id/video_playback_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<SeekBar
android:id="#+id/seekbar_video"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_below="#+id/video_playback_pause" android:clickable="true"/>
</RelativeLayout>
<VideoView
android:id="#+id/videoView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</LinearLayout>
EDIT:
You can use the visibilty property as below
android:visibility="invisible" // invisible- just invisible the controls not the space
//gone - removes the allocated space too
//visible- shows the control
At run time also you can change
mylayout.setVisibilty(View.GONE)...
When it comes to your seekbar, this could be the possible answer: Set
android:clickable="true"
and in your java code, try putting an Event Listener. For Event Listeners, http://developer.android.com/guide/topics/ui/ui-events.html
When it comes to your layout, you can try using a Linear Layout and then nest a Relative Layout inside it. You might have to change your xml a bit.
Answer for the first part of question.
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true">
The inner relativeLayout's visibility is set to invisible.Remove it.
You have provided android:clickable="" for seekbar. May be thats why its not working.
Remove that and try.
Hope this will help you.
I've got a question about how to define this really simple layout:
I'd like to use Relative Layouts but I'd need the B height to fill all the height that A leaves.
I'm trying to do a layout that suits for all the resolutions, so I cannot specify px or dp in the xml layout definition.
Ideally, I don't wanna use the wrap content property for height because B is a ListView.
Is there any solution at all?
Thanks
Layout image
Here
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/holder_a"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</LinearLayout>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/holder_a" >
</ListView>
</RelativeLayout>
<RelativeLayout >
<A fixed height />
<B layout_below=a fill_parent />
</RelativeLayout >
"I'm trying to do a layout that suits for all the resolutions"
Then you should do more than one XML file, else it's impossible to have 1 perfect layout for all devices, except Height of A is fixed
This will give you the layout that you want:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout android:id="#+id/linearLayout1" android:layout_height="60dp" android:layout_width="fill_parent"></LinearLayout>
<ListView android:id="#+id/listView1" android:layout_height="fill_parent" android:layout_width="fill_parent"></ListView>
</LinearLayout>
You can replace the inner LinearLayout with anything you want.
Use android:layout_weight
<LinearLayout
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:weightSum="100"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="70" >
</LinearLayout>
<LinearLayout android:id="#+id/widget32" android:orientation="horizontal"
android:layout_weight="30" android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout>
</LinearLayout>
How do I make my ads display at the bottom of the screen?
I have tried setting gravity to bottom but it still won't budge.
Current page code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/Background_Color">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:myapp="http://schemas.android.com/apk/res/com.x.x" >
<TextView android:id="#+id/out_text"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:textSize="30dip"
android:textColor="#color/Text_Color" />
<com.admob.android.ads.AdView
android:id="#+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
myapp:refreshInterval="10"
android:visibility="visible" />
</LinearLayout>
</ScrollView>
Any help would be greatly appreciated!
Try adding a weight to your TextView.
android:layout_weight="1"
This means, it will take up any open space of the parent.
And add this to the ScrollView:
android:fillViewport="true"
Try using a RelativeLayout instead, and give the AdView an attribute of android:layout_alignParentBottom="true".
Also, gravity only affects the content, layout_gravity affects the view itself. (You may know that, just pointing it out)