I am trying to put seekbar below Webview that shows Map.
However when i place the seekbar below WebView in main .xml, it doesn't come up. Can someone tell me what's wrong?
<?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"
>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webkit"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<SeekBar
android:id="#+id/frequency_slider"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="1"
android:progress="0"
android:progressDrawable="#drawable/seekbar_progress"
android:paddingLeft="4dip"
android:paddingRight="4dip"
/>
</LinearLayout>
Your WebView has height set to "fill_parent" and thus it will take up the whole screen. So your seek bar is getting pushed off the bottom. You have a few options: set the height for your webview to something smaller than "fill_parent" (some static value in dip units, or wrap_content). Or use a RelativeLayout instead of linear and make use of the layout_alignParentBottom="true" attribute for the seekbar. And layout_above="#+id/frequency_slider" for the WebView. There are other ways you could solve the problem, but those are the easiest two that come to mind for me.
Related
Hey I have a scrollview from the top of the screen to a bit before the bottom of the screen because this is where my ad banner takes place. I want to have some pixels in between these elements ( between buttons and banner ) due the google policy. So far I did this with setting a value in dp. But as devices differ, this results in having a huge gap between the ad and the scrollview on some hi-res phones. This is why I'd like to set
<ScrollView
android:layout_height="(Screen_height-banner)-5px"
(of course I didn't even try it in this way, as this is no code, but I think it sums up pretty well what I plan to do)
Thanks a lot for your answers!
You can't query screen size in XML since it doesn't run at runtime, you can do this by using RelativeLayout and use alignments and margins.
in your case if Screen_height-banner represent a screen height and you want to position it at bottom and make a 5dp separator from end your XML would be
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp">
</RelativeLayout >
If you need to scale the scroll view instead of position it you xml would be
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding_bottom="5dp">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent">
</RelativeLayout >
You can user weight parameter. If you set weight of both layouts 0.5, this will share screen width equals for these layouts.
<LinearLayout
android:id="#+id/alt_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/orta_panel" >
<LinearLayout
android:id="#+id/altsol_panel"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center_horizontal"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/altsag_panel"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center_horizontal"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
Use a RelativeLayout, set a Margin of 5px and use layout_above
If the following codes don't work for you, you're probably using a newer version of something, and you could try using android:bottom="80dp" instead of android:layout_marginBottom="5dp"
Hi,
I am trying to design a layout that has no dependency on screen size. Actually I am designing a sample layout in which there is a large size add in the center of screen. There is a text in the center of upper remaining area and lower remaining part. The xml is:
<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" >
<ImageView
android:id="#+id/ads_layout_large"
android:layout_width="300dp"
android:layout_height="250dp"
android:layout_centerInParent="true"
android:background="#android:color/background_light" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/ads_layout_large"
android:background="#fff000"
android:gravity="center"
android:text="#string/exit_enjoyed_text" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/ads_layout_large"
android:background="#fff000"
android:gravity="center"
android:text="#string/exit_enjoyed_text" />
</RelativeLayout>
The problem is, it is working on upper part, the text is exactly in the center of the remaining area, but the lower TextView has covered half of the screen, can you please help me find the mistake? Or any other way to design the same?
I think here is your problem :
android:layout_height="fill_parent"
setting your TextView height to fill_parent cause your textview extend to reach it's parent size , use wrap_content or static value like "30dp" instead
I have the following layout...
<?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"
android:background="#drawable/bg_generic_portrait">
<ListView android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/issue_list_item_background_normal"
android:listSelector="#drawable/issue_background_selector"
android:divider="#drawable/separator"
>
</ListView>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="#+id/preloader"
style="#android:style/Widget.ProgressBar.Large"/>
<TextView android:id="#android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"/>
</LinearLayout>
And it looks like this...http://i.stack.imgur.com/Ra5c6.png
I want the preloader to be centered vertically too, what is wrong?
Somehow the layout_gravity does not work well.
What you need to do is nest the progress_bar in a linear_layout and set the gravity of that layout to center, like this:
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/preloader"
style="#android:style/Widget.ProgressBar.Large"/>
</LinearLayout>
I do not suggest setting the gravity to the topmost linear layout because you could have funny things happening if you change the list or add something.
thats because you are using a LinearLayout, I suggest that you use a RelativeLayout
and have the attibute center using layout_centerVertical like this:
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:id="#+id/preloader"
style="#android:style/Widget.ProgressBar.Large"/>
There seems some problem with what you are trying to do. ListView on top of progress bar in your layout can have a variable height depending on its contents. So, it's not possible to ensure progress bar stays in center of screen using linear layout.
You may want to look at ProgressDialog class that will show a progress dialog while you load data into list in background.
Alternatively, you can make ProgressBar and ListView overlap by using RelativeLayout as top level layout and specify android:layout_centerInParent="true" attribute for ProgressBar
Set android:gravity="center" in your parent LinearLayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
I don't know how much space is your Listview taking, but you might want to use a <RelativeLayout> instead of <LinearLayout> if you want to really define where you want x item.
I'm trying to create a very simple android screen with the following content: top banner, webview and bottom banner. for some reason, i can't do it. my xml look like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/FrameLayout02"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"
android:fitsSystemWindows="true" android:isScrollContainer="false">
<ImageView android:layout_width="wrap_content" android:layout_above="#+id/Web"
android:layout_height="fill_parent" android:layout_gravity="top"
android:src="#drawable/logo"></ImageView>
<WebView android:layout_gravity="center" android:id="#+id/Web"
android:layout_height="fill_parent" android:layout_width="fill_parent"></WebView>
<ImageView android:layout_width="wrap_content" android:layout_below="#+id/Web"
android:layout_height="fill_parent" android:layout_gravity="bottom"
android:src="#drawable/logo"></ImageView>
</LinearLayout>
what is wrong?
Thanks,
Daniel
Short answer all is wrong. Your code is a mess.
Long answer. You are trying to have an ImageView above a WebView and at the bottom another ImageView. I'm not exactly sure what of the mistakes broke it but that's also not important. Take a look at my example XML 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="fill_parent">
<ImageView android:id="#+id/topimage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:src="#drawable/icon"/>
<ImageView android:id="#+id/bottomimage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:src="#drawable/icon"/>
<WebView android:id="#+id/web"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/topimage"
android:layout_above="#id/bottomimage"/>
</RelativeLayout>
Now what my XML does is simple. It uses a RelativeLayout as a container to allow a more flexible child alignment. The ImageView called topimage will adjust its height to its content and fill the parent in width. It is aligned to its parents top. The second ImageView is similar with the only exception that it is pinned to its parents bottom. The WebView is aligned in between both ImageViews. It adjust it's height to the 'ImageView`s heights.
Try to always keep some kind of structure in your XML and also Java code so you and also others can throw a look at it without starting to cry.
I am trying to draw some boxes in my activity, which will contain other layout elements, in XML. I want to do this using the relative dimensions, e.g. specify half of the height of the screen for each box. I understand that the correct way to do this is to set the initial height to 0px and use layout_weight, but I can't get the following example to work. I am expecting it to draw two identical rectangles (defined in /drawable/rect) in different vertical halves of the screen, but the screen is blank:
<?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="fill_parent">
<ImageView
android:src="#drawable/rect"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:scaleType="fitXY"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1"/>
<ImageView
android:src="#drawable/rect"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="fill_parent"
android:scaleType="fitXY"
android:layout_height="0px"
android:layout_weight="1"/>
</RelativeLayout>
Does anyone have any ideas?
Why is it?
android:layout_height="0px"
That makes the rectangles to have zero height, which might explain why they don't show up.