Android TabWidget White Space Issue - java

I am working on the TabWidget and i am getting a white space between the TabActivity and the Tabs.
I don't know how to remove this white space please can any one help me out how should i remove it, my tab_main.xml is as follows :
<?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" >
<TabHost
android:id="#android: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="0dip"
android:layout_weight="1" />
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" />
</LinearLayout>
</TabHost>
I tried to put background color of TabWidget to android:color:transparent but still same white space comes between the Activity and the Tab.
I do not want any separation space between my Activity and the Tabs (Is it possible to do it?)
Please can any one suggest me how to get rid of this white space.

The output you've shown most likely suggests a Margin/Padding error, rather than a layout error. Either your TabWidget or your FrameLayout could have a margin getting inherited by the overall theme that you're using.
Most likely the following will fix the problem (note the extra margin/padding styles):
<FrameLayout
android:layout_marginBottom="0dip"
android:layout_paddingBottom="0dip"
android:background="#android:color/holo_green_light"
android:id="#android:id/tabcontent"
....
.... />
<TabWidget
android:layout_marginTop="0dip"
android:layout_paddingTop="0dip"
android:background="#android:color/holo_blue_light"
android:id="#android:id/tabs"
....
.... />
Your FrameLayout could also have any nested components which have a margin/padding, and which in turn may cause the white space. I've added the android:background to both the FrameLayout and the TabWidget, just to help troubleshoot if there is any white space in between.
You said that you've tried putting background color of the TabWidget to transparent - but it won't help, because if there is a margin - then the underlying activity's background color shows up as white, below the transparent area. If you set the overall RelativeLayout's background color to something like blue - then you will see the blue coming through. So fix the margin/padding rather than trying to hide it.

It Look's Like you are having similar issue as i was having in my project, check out this project and try to implement the drawable xml files and provide your TabWidget with the specific custom dimensions as given in this project. It will surely work for you.

From your screen shot, it looks like you are using a WebView. Webview comes with a default margin and padding > 0. You can set the padding and margin to zero by overriding the WebView's body tag, or using css.
For further details, please see the answers to the following SO question:
Remove unwanted white space in webview

Related

App Widget: Ripple effect lost on list item when background is added to outer layout

This thing is driving me crazy. Here's how it works
1. everything is set as default
ripple effect works
list view item separator is visible
2. white background added to the widget layout
ripple lost
list view item separator also gone
looks like list item style has been removed
Here's the code
main widget layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
...
android:background="#android:color/white" -- this line only applies for case 2
android:padding="#dimen/widget_padding">
<TextView
...
android:background="#color/primary"
android:textColor="#android:color/white"/>
<ListView
...
android:drawSelectorOnTop="true""/>
<TextView
...
android:textColor="?android:attr/textColorSecondary"/>
</LinearLayout>
list item layout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
...
android:id="#+id/widgetItem">
<TextView
...
android:textColor="#android:color/black"
android:textSize="14sp"/>
<TextView
...
android:textColor="#color/negative_amount"
android:textSize="16sp"
android:textStyle="bold"/>
</RelativeLayout>
I've spent a day trying all possible combinations but nothing helped. And I don't get the fact that unrelated background change to some layout around the list view completely alters the behaviour. WTF?
I would like to solve it in the cleanest way possible - e.i. no hacking with custom selectors. This should work straight out of the box if possible.
It looks like you're using a dark theme for your activity, so the ripple is white and thus not visible over a white background. The simplest solution is to use a light variant of the theme, which will cause the ripple to be black.
For example, if you're using an AppCompat theme, you can add this line to your ListView:
<ListView
...
android:drawSelectorOnTop="true"
style="#style/Theme.AppCompat.Light"/>
You can also apply this to a view hierarchy, e.g.:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
...
android:background="#android:color/white"
android:padding="#dimen/widget_padding"
android:theme="#style/Theme.AppCompat.Light">
This will cause the theme to be used in the LinearLayout and all of its child views.
Also, you can specify a theme activity-wide or even app-wide by adding android:theme attribute to the <activity> or <application> tag to your AndroidManifest.xml.

Baseline aligned TextView clips bottom line of multi-line text

I would like the items in a ListView in my android app to contain a check box on the left, followed by some text, followed by a button. I would like the check box and button to be baseline aligned with the text. To achieve this, I put all three in a LinearLayout which tries to baseline align its items by default. This works great, except that the bottom line of multi-line text is always clipped.
Here is an example of how it looks:
There is a related question on StackOverflow with the proposed solution to be to set layout_gravity = "fill" for the TextView, but that defeats the purpose as it disables the baseline align. Is there any solution to this problem that allows me to preserve the baseline align? This seems like a pretty basic problem that surely many people must encounter.
The only other solution I've found is to add some padding to the bottom of the text view, but this seems hacky and not robust against font sizes. I could set the padding procedurally from code based on the font size, but it seems like it may be tricky to get the correct values.
Here is a sample layout that illustrates the problem:
<?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="wrap_content"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:baselineAligned="true">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="9dp"
android:layout_marginRight="8dp"
android:textSize="16sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Woah, this is a long text line, enough that tit has to wrap to multiple lines, thus demonstrating our problem. In fact, it wraps to multiple lines! So many lines! I hope they all show up correctly!"
android:textSize="16sp"/>
<FrameLayout
android:layout_width="40dp"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="12dp"
android:src="#drawable/ic_note_check_delete"/>
</FrameLayout>
</LinearLayout>

Customize position of handle of sliding drawer

I had researched many sources and tried but still cannot move the position of handle from center to right.
<SlidingDrawer
content >
<ImageButton <-- this is handle
android:id="#+id/handle" <-- i want to customize position
android:layout_width="50px"
android:layout_height="60px"
android:background="#drawable/icon_other" />
<LinearLayout
android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_others"
android:orientation="vertical" >
//content
</LinearLayout>
</SlidingDrawer>
So what to do to customize the position?
Please give opinion. Thanks
Use a TableLayout. This works similar to a HTML Table concept, allowing you to define rows and columns where to place buttons and other components.
If you don't want to use a table layout for the entire screen, you should be able to nest the layout within another....

Is it possible to include a MapView as an element of another activity?

Just as the title says...I want to include a MapView inside of another activity. For instance, I want the MapView to take up half of the screen, and below that, include some other widgets - text fields, buttons, whatever. I have been tinkering with it, but so far I have been unsuccessful - the map does take up only half the screen, but no widgets show up.
Any clues? Is this possible, or is the Google Map integration strictly using the map as a full screen?
Please post your xml layout!
You are just doing it wrong. :-D
A mapview will work like any other widget. I strongly believe there is a mistake in your layout.
This one will work for instance!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/h1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<CheckBox
android:text="Satellite"
android:id="#+id/satellite"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<ImageView
android:id="#+id/image"
android:layout_width="75dip"
android:layout_height="75dip"
android:layout_marginRight="6dip"
android:src="#drawable/uoicon" />
</LinearLayout>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0zDdYFYf6Ir2W-NuiHPLAoFjsq0nmqRhPfzjY3A"/>
</LinearLayout>
Just a guess but you're using a LinearLayout to contain the MapView and other widgets but you forgot to set the orientation to vertical? The default for LinearLayout is horizontal.
It came to mind because it's something I've done 2 or 3 times myself. Totally confusing as effectively the other widgets 'disappear' off the right-hand side of the screen. It eventually got engrained in my mind and I always make sure to explicitly specify orientation now when I use LinearLayout.

Android FrameLayout can't set a View visible when it's initially set to invisible

I have met a very strange issue in android FrameLayout.
I am trying a very simple game which has a SurfaceView, and when the game ends, I want to popup another view on top probably displaying some text. This is very similar to android sample lunarlander code. However I can't get it work. Here is the strange issue:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/game_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.tmh.FunMatch.MainGamePanel
android:id="#+id/game_panel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.tmh.FunMatch.MyText
android:id="#+id/text"
android:text="test"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:textColor="#88ffffff"
android:textSize="24sp"/>
</RelativeLayout>
For above FrameLayout, I want to show the second TextView when game finished. However it won't show after I call TextView.setVisibility(VISIBLE).
I did a lot experiment, if I initially set the TextView as VISIBLE, then at some point set it to INVISIBLE in the code. (My understanding is the TextView must be initially showed on the screen once then I turned it into INVISIBLE). If I did so, when the game finished, the TextView will be correctly shown.
I highly doubt it's an android bug. I changed android LunarLander code, I don't know why LunarLander did work and show the Text on the screen.
If anyone had run into the same issue, please tell me what's wrong with my code or is there a hidden bug?
Thanks

Categories

Resources