I'm having a problem with an Android APP that seems related to layout. Attached image you'll see that the "Alerts" button sticks out and doesn't seem the same as the other buttons. I've replaced the image with a known good one, but the problem remains.
It was suggested it was because it is tabhost layout, but all the changes that have been recommended have not worked. So far I've tried changing the attributes from android:height and width to "wrap_content", "fill_parent", and "match_parent". Match caused another strange white space to be corrected, but this button is my last apparent challenge.
Here's the layout code, can you tell me what the problem is?
<?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:orientation="horizontal" >
<Button
android:id="#+id/btnSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/job_tab_bar_search"
android:focusable="false"
android:freezesText="false"
android:imeOptions="actionNext"
android:longClickable="false"
android:paddingLeft="17dp"
android:text="Search"
android:textColor="#color/color_text_default"
android:textSize="12dp"
android:visibility="visible" />
<Button
android:id="#+id/btnHistory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/job_tab_bar_history"
android:paddingLeft="25dp"
android:text="History"
android:textColor="#color/color_text_default"
android:textSize="12dp" />
<Button
android:id="#+id/btnFavorites"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/job_tab_bar_favorites"
android:paddingLeft="30dp"
android:text="Favorites"
android:textColor="#color/color_text_default"
android:textSize="12dp" />
<Button
android:id="#+id/btnAlerts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/job_tab_bar_alerts"
android:paddingLeft="12dp"
android:text="Alerts"
android:textColor="#color/color_text_default"
android:textSize="12dp" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
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="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.32" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TabWidget>
</LinearLayout>
</TabHost>
You'd think someone would have replied, in the end it was stupid simple.
The answers is:
Tabhost using tabactivity will display the background through menu items if they are re-sized. Add a color coded (html notation) color to the schema, then call that with the android:border-background construct.
Related
I'm new in the world of Android development, and I'm trying to learn how to getting started from here.
Now I've followed all steps until to put the Zip Code and the Number on the same line. I don't understand how can I manage this, if I drag and drop the Number control beside the TextView the IDE put the Number above the control or to the bottom. I don't know how to explain correctly, anyway, this is an image:
and this is the source code:
<?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">
<RelativeLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/relativeLayout1" />
<EditText
android:inputType="number"
android:layout_height="wrap_content"
android:id="#+id/ZipCodeEdit"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:layout_width="100sp"
android:textColor="#9933FF" />
<TextView
android:text="Zip Code: "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ZipCodeLabel"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:textSize="20sp" />
</LinearLayout>
from the site should be like this:
what is wrong? Sorry if something is not clear, or if the category tag is wrong.
Try 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" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="25px"
android:minWidth="25px" >
<EditText
android:id="#+id/ZipCodeEdit"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:inputType="number"
android:textColor="#9933FF"
android:textSize="20sp" />
<TextView
android:id="#+id/ZipCodeLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/ZipCodeEdit"
android:text="Zip Code: "
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>
You should make proper use of LinearLayout, RelativeLayout, FrameLayout and TableLayout for the desired alignments.
Here is your solution.:
<?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">
<RelativeLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/relativeLayout1" >
<EditText
android:inputType="number"
android:layout_height="wrap_content"
android:id="#+id/ZipCodeEdit"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:layout_width="100sp"
android:textColor="#9933FF" />
<TextView
android:text="Zip Code: "
android:layout_width="match_parent"
android:layout_toRightOf="#+id/ZipCodeEdit"
android:layout_height="wrap_content"
android:id="#+id/ZipCodeLabel"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>
What you were doing Wrong :
You are trying to align EditText and TextView one beside another inside RelativeLayout but you've closed the relative layiut right where it started.
that makes the EditText and TextView the child view of the LinearLayout(Vertical)
As the text views are behaving as the children of Linear vertical layout there is no use of RelativeLayout hence aligning both views one below another.
One more thing when you fix that and put both the text view within RelativeLayout you have to align one view in relation with the another.
In this case:
android:layout_toRightOf="#+id/ZipCodeEdit"
Let me know if any problem.
Happy Coding
You are using a vertical LinearLayout as the parent layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
Change android:orientation="vertical" to android:orientation="horizontal".
You can also remove the RelativeLayout as it's not really being used(nothing inside it).
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:inputType="number"
android:layout_height="wrap_content"
android:id="#+id/ZipCodeEdit"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:layout_width="100dp"
android:textColor="#9933FF" />
<TextView
android:text="Zip Code: "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ZipCodeLabel"
android:layout_marginLeft="10dp"
android:textSize="20sp" />
</LinearLayout>
This should fix your problem. I will explain if this works for you.
Ive got the problem that, when i click one of the buttons shown in xml below, the text on the button jumps down one line. So if the button is 1 line, no text is shown. If the button is 2 lines, only the first line is shown, in the buttom of the button.
Nothing in the onClick method changes the layout.
Heres the XML
<?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"
android:id="#+id/layout_main">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
.. a few other layouts and controls that works fine
<TableLayout
android:id="#+id/tableLayout276"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/TableRow10"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="#+id/BtnRet"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Ret"
android:gravity="center"
android:textSize="18dp" />
<Button
android:id="#+id/BtnVisningsType"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Decimaltal"
android:gravity="center"
android:textSize="18dp" />
<Button
android:id="#+id/BtnFunktioner"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Funktioner"
android:gravity="center"
android:textSize="18dp" />
</TableRow>
</TableLayout>
.. a few other layouts and controls that works fine
</LinearLayout>
</ScrollView>
</LinearLayout>
Now, if i change the layout_width on the buttons to wrap_content, it all works fine (got the idea from When changing textview, the text on a button below the textview moves down. Help! ) - except the buttons now obviusly dont have the same width, and it looks messy.
Does anyone have any idea why this happens, and how i can both keep the text, and decide the size of the buttons?
This adds complexity to the layout but might be a solution.
Add a LinearLayout to your table row and use weights to control precise layout of your buttons. Something like this:
<TableRow
android:id="#+id/TableRow10"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
android:weightSum="3"
android:orientation="horizantal"/>
<Button
android:id="#+id/BtnRet"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Ret"
android:gravity="center"
android:textSize="18dp" />
<Button
android:id="#+id/BtnVisningsType"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Decimaltal"
android:gravity="center"
android:textSize="18dp" />
<Button
android:id="#+id/BtnFunktioner"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Funktioner"
android:gravity="center"
android:textSize="18dp" />
</LinearLayout>
</TableRow>
Caveats:
Might give a performance hit
Typed from memory, please excuse any typos
Not tested
use padding/margin to adjust precise sizing
A RelativeLayout might also work.
Been struggling with this for a while now. I have a layout XML consisting of various LinearLayouts, with separate weighting. The end result looks like this..
Dont mind the colors, its just to see the break points..Anyway, below the Terminal/Origin etc LinearLayout is a ListView which is populated using a custom adapter. The data loads fine, but then the listView "breaks out" of the LinearLayout, and takes up most of the page
(Dont mind the colors, its just to see the break points..)
ie. it flows over the View above and below.
My XML is as follows:
<?xml version="1.0" encoding="utf-8"?>
<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:ignore="HardcodedText" >
<RelativeLayout
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:background="#FF0000"
android:gravity="right" >
<Button
android:id="#+id/update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:onClick="getFlightInfo"
android:text="Refresh" />
</RelativeLayout>
<LinearLayout
android:id="#+id/table_header"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="0.4"
android:background="#FFFFFF"
android:weightSum="1" >
<TextView
android:id="#+id/header_cell1"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="#string/cell_1_weight"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:paddingRight="12dp"
android:text="#string/table_header_terminal"
android:textSize="11dp" />
<TextView
android:id="#+id/header_cell2"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="#string/cell_2_weight"
android:gravity="center_vertical"
android:paddingRight="12dp"
android:text="#string/table_header_origin"
android:textSize="11dp" />
<TextView
android:id="#+id/header_cell3"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="#string/cell_3_weight"
android:gravity="center_vertical"
android:paddingRight="12dp"
android:text="#string/table_header_flight"
android:textSize="11dp" />
<TextView
android:id="#+id/header_cell4"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="#string/cell_4_weight"
android:gravity="center_vertical"
android:paddingRight="12dp"
android:text="#string/table_header_scheduled"
android:textSize="11dp" />
<TextView
android:id="#+id/header_cell5"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="#string/cell_5_weight"
android:gravity="center_vertical"
android:paddingRight="12dp"
android:text="#string/table_header_status"
android:textSize="11dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/table_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:background="#FFFFFF"
android:orientation="vertical" >
<ListView
android:id="#+id/list_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/filter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00FF00" />
</LinearLayout>
I may be missing something glaring, but for the life of me, I cant see it. Can anyone help?
Thanks a million..
This is because you have kept LinearLayout's height(the one wrapping listview) "wrap_content".Fixing its size to some dip would solve your problem.
Also make listview's height "fill_parent" then.
EDIT :
try this way:
...
<ListView
android:id="#+id/list_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ListView>
in upper two layouts,you user 0.2 and 0.4 as weight but in lower two layouts,you users 3 and 1...try it former way and see,if it can help you.also try making height of LinearLayout(the one wrapping listview) to 0dip.
Maybe it is late, but I could help someone.
<?xml version="1.0" encoding="utf-8"?>
<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"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff0000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="Content 1" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#00ff00">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="Content 2" />
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/linearLayout2"
android:layout_below="#id/linearLayout1"
android:background="#00f0f0"></ListView>
Result:
Ok.. after consulting this post I came up with a fix
Remove the LinearLayout outside the ListView, its superfluous.
Add a height of '0px' (which I've found around the web) to the ListView ensures it obeys the android:weight parameter properly.
Hope this helps.
Remove the weight of id/filter.
Let the ListView have a weight of 1 with fill_parent height.
Remove the listView's immediate parent.
One other thing you missed, is to set the weightSum=sum_of all_child_weight in your root. That should fix the problem.
I am having issues with creating a menu (not menu when you click menu button -- but menu as in the welcome screen to select items). I went to ImageView and TextView float (left/right) Android and I did not solve my issue. I would like to create at least five or six options to select from on this menu class. This is my menu.xml file. Please let me know what I need to do.
The issue is that the first item appears, but the second item overlaps the first item. I been picking away with this for the last hour and cannot solve this issue.
<?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:padding="5dp">
<TextView
android:textSize="18dp"
android:id="#+id/message_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Check Your Account" />
<ImageView
android:src="#drawable/ic_menu_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/icon" />
<TextView
android:textSize="18dp"
android:id="#+id/message_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" View our Site" />
<ImageView
android:src="#drawable/ic_menu_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
thannk you.
Why don't you use a LinearLayout (like a vertical one with severals little horizontal ones inside, each with a TextView and an ImageView) ?
Anyway, if you want to use RelativeLayout you should use something like android:layout_toRightOf, android:layout_toLeftOf, android:layout_above or android:layout_below in your xml to place your elements.
I advise you to take a look at http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html if you don't know those parameters.
You use a RelativeLayout but you don't place elements with reference to each other.
Example :
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="#+id/topBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Top"
android:layout_centerHorizontal="true">
</Button>
<Button android:id="#+id/leftBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Left"
android:layout_below="#+id/topBtn"
android:layout_toLeftOf="#+id/topBtn">
</Button>
</RelativeLayout>
http://developer.android.com/reference/android/widget/RelativeLayout.html
A Linear Layout would be better.
Try this and tell me if this is what you needed:
<?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:padding="5dp"
android:orientation="vertical"
>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/message_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Check Your Account"
android:textSize="18dp" />
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_add" android:layout_gravity="center_horizontal"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/message_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" View our Site"
android:textSize="18dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_add" android:layout_gravity="center_horizontal"/>
</LinearLayout>
</LinearLayout>
So, I've seen several instances of padding being a problem in a custom title bar but this seems to be unique and I would love to see if anyone could shed some light on it.
Here's what I have:
There's padding to the right of the configure button that shouldn't be. I want a little bit of padding in the end but, to prove a point, this is with no padding set. Here's the layout for the custom title bar.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFF" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/titleImage"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="8dip"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:src="#drawable/icon" />
<TextView android:id="#+id/customtitlebar"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="COMPANY"
android:textSize="20dip"
android:textColor="#205cc7"
android:textStyle="bold"
android:paddingTop="15px" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:src="#drawable/configure" />
</LinearLayout>
</RelativeLayout>
I thought maybe the layout I gave a dummy id "container" was being cut off as well and the problem was outside this layout, but, when I change its background to red, it takes up the whole screen.
Does anyone have a solution short of hiding the OS title bar and making it a header for every screen layout?
Try to set android:layout_alignParentRight="true" to the LinearLayout which should be strechted to the right edge of the RelativeLayout.
Apart from that I agree to Octavian Damiean that your definition is to complex to receive the layout you want.
This layout has the same problem that the first image does. It uses alignParentRight and simplifies the layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFF" >
<ImageView
android:id="#+id/titleImage"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="8dip"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:src="#drawable/icon" />
<TextView android:id="#+id/customtitlebar"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="55dip"
android:text="COMPANY"
android:textSize="20dip"
android:textColor="#205cc7"
android:textStyle="bold"
android:paddingTop="15px" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:src="#drawable/configure" />
</RelativeLayout>