I want to add separator in between button and textview in my layout header contains 2 buttons and textview how do I add separator in between them?
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="50px"
android:layout_gravity="fill_horizontal"
android:background="#color/Blue"
android:orientation="horizontal" >
<Button
android:id="#+id/Back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:background="#color/Blue"
android:textSize="20sp"
android:textColor="#color/White"
android:text=" Back"
/>
<TextView
android:id="#+id/header_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:layout_toLeftOf="#+id/Exit"
android:layout_toRightOf="#+id/Back"
android:textSize="20sp"
android:textStyle="italic"
android:typeface="serif"
android:background="#color/Blue"
android:textColor="#color/White"
android:text="Games Apps"/>
<Button
android:id="#+id/Exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="20sp"
android:layout_centerVertical="true"
android:background="#color/Blue"
android:textColor="#color/White"
android:layout_marginRight="5dp"
android:text=" Exit"
/>
</RelativeLayout>
Seems that you need a vertical separator:
<TextView
android:layout_width="2dp"
android:layout_height="fill_parent"
android:layout_toLeftOf="#id/header_text"
android:layout_toRightOf="#id/Back"
android:background="#00000000"
/>
add View between your button and textview
For instance
<View
android:layout_width="2dip"
android:layout_height="fill_parent"
android:layout_toLeftOf="#id/header_text"
android:layout_toRightOf="#id/Exit"
android:padding = "5dip"
android:background="#FFFF0000"
/>
May this help you..
To add seperator you have to add a view in between the objects you want seperator..
like..
<View
android:layout_width="2dip"
android:layout_height="fill_parent"
android:layout_toLeftOf="#id/header_text"
android:layout_toRightOf="#+id/Back"
android:padding = "5dip"
android:background="#FFFF0000"
/>
and change this lines in your code..
<TextView
android:id="#+id/header_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_toLeftOf="#+id/Exit"
android:layout_toRightOf="#+id/Back"
android:textSize="20sp"
android:textStyle="italic"
android:typeface="serif"
android:background="#color/Blue"
android:textColor="#color/White"
android:text="Games Apps"/>
or you can use <TableRow> </TableRow> try to put the whole code with seperator in between the views
Try this, just workaround worked for me. You can use the same logic by implementing other Layout to instead of TableLayout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:showDividers="middle"
android:layout_centerInParent="true"
android:background="#000000"
android:divider="#000000"
>
<TableRow>
<Button
android:id="#+id/Back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:background="#ffffff"
android:textSize="20sp"
android:text=" Back"
/>
<TextView
android:id="#+id/header_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:layout_toLeftOf="#+id/Exit"
android:layout_toRightOf="#+id/Back"
android:textSize="20sp"
android:layout_marginLeft="1dp"
android:textStyle="italic"
android:background="#ffffff"
android:typeface="serif"
android:text="Games Apps"/>
<Button
android:id="#+id/Exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="20sp"
android:layout_marginLeft="1dp"
android:background="#ffffff"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:text=" Exit"
/>
</TableRow>
</TableLayout>
</RelativeLayout>
Let me know you have other difficulties use this.
Related
I have an issue trying align textView to the center of layout: when I try to do this - it has a conflict with a button on the left - if text is too long - it become hidden under the button. Text length can be very different and I need it in the center of layout but not under/on the button.
Here is the xml file of activity layout:
<?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="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/item_content_action_bar_layout"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/colorBlue"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:autoText="false"
android:layout_centerInParent="true"
android:layout_alignWithParentIfMissing="false"
android:layout_alignParentRight="false" />
<ImageButton
android:layout_width="120dp"
android:layout_height="45dp"
android:id="#+id/item_content_back_button"
android:background="#drawable/back_button_selector"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginRight="5dp" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/item_content_scroll_view"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="125dp"
android:layout_height="125dp"
android:id="#+id/item_content_image"
android:src="#drawable/ic_no_thumbnail"
android:maxHeight="125dp"
android:maxWidth="125dp"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="true"
android:layout_margin="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_subtitle"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Subtitle"
android:layout_alignTop="#+id/item_content_image"
android:layout_toRightOf="#+id/item_content_image"
android:layout_toEndOf="#+id/item_content_image"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_pubdate"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Date"
android:layout_below="#+id/item_content_subtitle"
android:layout_alignLeft="#+id/item_content_subtitle"
android:layout_alignStart="#+id/item_content_subtitle"
android:textSize="10dp"
android:layout_marginTop="10dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="blabla"
android:layout_below="#+id/item_content_pubdate"
android:layout_alignStart="#+id/item_content_pubdate"
android:layout_alignParentStart="true"
android:layout_margin="10dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Try using LinearLayout with layout-weight for this to avoid conflict. Change your first relativelayout to below one
<LinearLayout
android:id="#+id/item_content_action_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/_white"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="7">
<ImageButton
android:id="#+id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="2"
android:background="#drawable/chemist" />
<TextView
android:id="#+id/item_content_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="5"
android:autoText="false"
android:gravity="center"
android:maxLines="2"
android:singleLine="true"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/Black"
android:textStyle="bold" />
</LinearLayout>
Change Your RelativeLayout to LinearLayout and use android:layout_weight attribute of layout to do this.
<LinearLayout
android:id="#+id/item_content_action_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/_white"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="1"
>
<ImageButton
android:id="#+id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#drawable/chemist" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="1"
android:autoText="false"/>
</LinearLayout>
Make the layout_gravity of the textview item_content_title as "center_horizontal".
And add android:layout_toLeftOf="#+id/item_content_title" under the ImageButton item_content_back_button.
Hope it was what you wanted.
Your Action bar layout has to be like this-
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/item_content_action_bar_layout"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/colorBlue"
android:padding="10dp">
<ImageButton
android:layout_width="120dp"
android:layout_height="45dp"
android:id="#+id/item_content_back_button"
android:background="#drawable/back_button_selector"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dp" />
<TextView
android:toRightOf="#id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:autoText="false"
android:layout_centerInParent="true" />
</RelativeLayout>
I have an ImageView (android:id="#+id/unreadmail) which i want to show on extreme left of ListItem as shown in image. But it is not aligning properly. Any idea if i am missing anything ?
<LinearLayout
android:id="#+id/Text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/emailsubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:singleLine="true"
android:text="abcd"
android:textColor="#444444"
android:textSize="18sp" />
<TextView
android:id="#+id/emailcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/emailsubject"
android:layout_below="#id/emailsubject"
android:ellipsize="marquee"
android:gravity="center"
android:singleLine="true"
android:text="defg"
android:textColor="#444444"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:id="#+id/unreademail"
android:layout_width="2dip"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/emailsubject"
android:layout_centerVertical="true"
android:background="#8A6175"
android:visibility="invisible" />
<TextView
android:id="#+id/rcvdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingRight="20dip"
android:textColor="#313132"
android:textSize="12sp" />
Use this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity"
tools:ignore="ObsoleteLayoutParam,ContentDescription,UselessLeaf,UselessParent" >
<LinearLayout
android:id="#+id/Text"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/unreademail"
android:layout_width="15dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/ic_launcher"
android:visibility="visible" />
<LinearLayout
android:id="#+id/Text"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginLeft="20dp"
android:orientation="vertical" >
<TextView
android:id="#+id/emailsubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:singleLine="true"
android:text="abcd"
android:textColor="#444444"
android:textSize="18sp" />
<TextView
android:id="#+id/emailcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/emailsubject"
android:layout_below="#id/emailsubject"
android:ellipsize="marquee"
android:gravity="center"
android:singleLine="true"
android:text="defg"
android:textColor="#444444"
android:textSize="14sp" />
</LinearLayout>
<RelativeLayout
android:id="#+id/Text1"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:gravity="right"
android:layout_gravity="right"
android:orientation="horizontal" >
<TextView
android:id="#+id/rcvdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="35dp"
android:text="Date"
android:textColor="#000"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
I think you should be using a relative layout at the top level (possibly not included in your code).
You cannot use 'to the left of' when the elements are at different levels in the heirarchy.
Thus I would start with your little icon left aligned to the parent and put the edit box (in the same relative view) 'to the right of' the icon.
This is the code sample for you there is no need to write the weight property if add the screenshot or the supported image how exactly you want then i can give you proper answer
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/unreademail"
android:layout_marginLeft="10dip"
android:orientation="vertical">
<TextView
android:id="#+id/emailsubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:singleLine="true"
android:text="abcd"
android:textColor="#444444"
android:textSize="18sp" />
<TextView
android:id="#+id/emailcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/emailsubject"
android:layout_below="#id/emailsubject"
android:ellipsize="marquee"
android:gravity="center"
android:singleLine="true"
android:text="defg"
android:textColor="#444444"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:id="#+id/unreademail"
android:layout_width="2dip"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#8A6175"
android:visibility="invisible" />
<TextView
android:id="#+id/rcvdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingRight="20dip"
android:textColor="#313132"
android:textSize="12sp" />
</RelativeLayout>
i wan tto create sccreen like this image http://imgur.com/UVKCZdu my screen url is looklike this http://imgur.com/gLQw4iV
my screen not adjust facebook twitter iccon also show space on bottom below 3 buttons how do i fixed them? help me below is my xml code
<?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:background="#ffffff"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#C0C0C0" >
<ImageView
android:id="#+id/test_button_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingTop="5dp"
android:src="#drawable/icon" >
</ImageView>
<TextView
android:id="#+id/test_button_text2"
android:layout_width="wrap_content"
android:paddingTop="10dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/test_button_image"
android:paddingLeft="10dp"
android:layout_toRightOf="#+id/test_button_image"
android:text="San Diego Unified"
android:textColor="#000000"
android:textSize="20sp" >
</TextView>
<TextView
android:id="#+id/test_button_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:layout_alignLeft="#+id/test_button_text2"
android:layout_below="#+id/test_button_text2"
android:paddingBottom="10dp"
android:text="SCHOOL DISTRICT"
android:textColor="#000000" >
</TextView>
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="40dp"
a
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="left|center_vertical"
android:singleLine="true"
android:text="HEALTHY BODIES HEALTHY MINDS "
android:textColor="#000000"
android:textSize="12sp" />
<ImageButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:src="#drawable/facebook" />
<ImageButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:src="#drawable/twitter"
android:text="Button Text" />
</LinearLayout>
<RelativeLayout
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Search School By Name"
android:layout_centerVertical="true" >
</EditText>
<ImageView
android:id="#+id/imageView1"
android:padding="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/editText1"
android:layout_alignBottom="#+id/editText1"
android:layout_alignRight="#+id/editText1"
android:src="#drawable/title_search" />
</RelativeLayout>
<TextView
android:id="#+id/txtCaption"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:paddingBottom="3dp"
android:paddingLeft="10dp"
android:paddingTop="3dp"
android:text="SELECT A SCHOOL TO VIEW LUNCH OR BREAKFAST MENUS"
android:textColor="#000000"
android:textSize="10sp"
android:textStyle="bold" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#000000" />
<LinearLayout
android:id="#+id/lytContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/txtCopyright"
android:background="#ffffff"
android:layout_below="#+id/lytTitlebar"
android:orientation="vertical" >
<ListView
android:id="#+id/listMainMenu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#color/background"
android:dividerHeight="1dip"
android:fadeScrollbars="true" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#a8a8a8"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#a8a8a8"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.333"
android:background="#drawable/button_style"
android:text="FARM TO SCHOOL"
android:textColor="#color/text"
android:textSize="8sp"
android:textStyle="bold" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.333"
android:background="#drawable/button_style"
android:text="TAKE A SURVEY"
android:textColor="#color/text"
android:textSize="8sp"
android:textStyle="bold" />
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.333"
android:background="#drawable/button_style"
android:text="SHARE THIS APP"
android:textColor="#color/text"
android:textSize="8sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
You can't setText in an ImageView.. that's just for TextViews
What you can do instead is wrap an ImageView and a TextView inside a FrameLayout, then do your setText on the TextView. Make sure you define the ImageView first, so it's below the TextView's z-order.
Add image to text view like this:
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:drawableRight="#drawable/protection_unprotected"
android:gravity="center_vertical"
android:paddingRight="5dp"
android:text="#string/protection_unprotected"
android:textSize="18sp"
android:textStyle="bold" />
android:drawableRight="#drawable/protection_unprotected"
For your Facebook and Twitter buttons you can add
android:background = "#null"
inside ImageButton tags for the unwanted background in buttons.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#a8a8a8"
android:orientation="horizontal" >
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/headerLinearLay"
android:orientation="horizontal">
<ImageView
android:id="#+id/avatarImageView"
android:src="#drawable/icon"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<TextView
android:id="#+id/usernameTextView"
android:text="TextView"
android:paddingLeft="4dp"
android:layout_toRightOf="#id/avatarImageView"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></TextView>
</RelativeLayout>
</LinearLayout>
I try to create somekind of stroke on top of my screen which displays 4 things. An backbutton on the left, the level name in the center and scoreInfoOne and scoreInfoTwo on the right, but below each other. I use following code, but the strange thing is that the level name doesn't appear to be centered, the longer the value of scoreInfoTwo is, the more the level name is on the left. Any ideas?
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="35dp"
android:background="#25ab89"
android:orientation="horizontal"
android:weightSum="4" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/ivBackButton"
android:layout_width="18dp"
android:layout_height="18dp"
android:src="#drawable/arrow" />
</LinearLayout>
<TextView
android:id="#+id/tvScoreBoard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:gravity="center"
android:text="level"
android:textColor="#ffffff"
android:textSize="18dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical"
android:paddingRight="2dp" >
<TextView
android:id="#+id/tvScoreInfoOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="0/30"
android:textColor="#ffffff"
android:textSize="12dp" />
<TextView
android:id="#+id/tvScoreInfoTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="score:"
android:textColor="#ffffff"
android:textSize="12dp" >
</TextView>
</LinearLayout>
Your child views must set the layout_width to zero:
android:layout_width="0px"
So your layout would then look like:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="35dp"
android:background="#25ab89"
android:orientation="horizontal"
android:weightSum="4" >
<LinearLayout
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/ivBackButton"
android:layout_width="18dp"
android:layout_height="18dp"
android:src="#drawable/arrow" />
</LinearLayout>
<TextView
android:id="#+id/tvScoreBoard"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:gravity="center"
android:text="level"
android:textColor="#ffffff"
android:textSize="18dp" />
<LinearLayout
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical"
android:paddingRight="2dp" >
<TextView
android:id="#+id/tvScoreInfoOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="0/30"
android:textColor="#ffffff"
android:textSize="12dp" />
<TextView
android:id="#+id/tvScoreInfoTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="score:"
android:textColor="#ffffff"
android:textSize="12dp" >
</TextView>
</LinearLayout>
First off, you cannot use android:layout_gravity="anything" in a LinearLayout. For LinearLayouts you use the weights to define how much space you want to use. For what you are trying to do, I suggest using a RelativeLayout then you can just define where you want your TextView or other items by using android:layout_below="#+id/other_textview and there are lots of android:layout_[direction] to choose from, and you can use layout_gravity="center_horizontal" with these.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="35dp"
android:background="#25ab89">
<ImageView
android:id="#+id/ivBackButton"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/arrow" />
<TextView
android:id="#+id/tvScoreBoard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_below="#id/ivBackButton"
android:gravity="center"
android:text="level"
android:textColor="#ffffff"
android:textSize="18dp" />
<TextView
android:id="#+id/tvScoreInfoOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_below="#id/tvScoreBoard"
android:alignParentRight="true"
android:text="0/30"
android:textColor="#ffffff"
android:textSize="12dp" />
<TextView
android:id="#+id/tvScoreInfoTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_below="#id/tvScoreInfoTwo"
android:alignParentRight="true"
android:text="score:"
android:textColor="#ffffff"
android:textSize="12dp" />
</RelativeLayout>
This layout is used as the layout for items in a listView. I had a really simple layout, and everything was working fine, but now i have changed it a little and it is crashing my app when it tries to load.. Not sure what im doing wrong
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:weightSum="8"
android:layout_width="fill_parent"
android:layout_height="75dp">
<TextView android:id="#+id/priceText"
android:layout_weight="2"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp" />
<LinearLayout
android:layout_weight="5"
android:layout_height="fill_parent"
android:weightSum="2"
android:orientation="vertical">
<TextView android:id="#+id/storeText"
android:layout_width="fill_parent"
android:layout_weight="1"
android:gravity="right|bottom"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView android:id="#+id/distanceText"
android:layout_width="fill_parent"
android:layout_weight="1"
android:gravity="right|top"
android:textSize="16dp"
android:textColor="#545454"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
</LinearLayout>
<TextView
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|center_vertical"
android:text=">"
android:textColor="#000000"
android:textSize="36dp"
android:textStyle="bold"
android:layout_marginRight="5dp" />
</LinearLayout>
When you use android:layout_weight put layout_width="0dip"
Working code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:weightSum="8"
android:layout_width="fill_parent"
android:layout_height="75dp">
<TextView android:id="#+id/priceText"
android:layout_weight="2"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp" />
<LinearLayout
android:layout_weight="5"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:weightSum="2"
android:orientation="vertical">
<TextView
android:id="#+id/storeText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|bottom"
android:textColor="#000000"
android:textSize="22dp"
android:textStyle="bold" />
<TextView
android:id="#+id/distanceText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|top"
android:textColor="#545454"
android:textSize="16dp" />
</LinearLayout>
<TextView
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|center_vertical"
android:text=">"
android:textColor="#000000"
android:textSize="36dp"
android:textStyle="bold"
android:layout_marginRight="5dp" />
</LinearLayout>
You need to add android:layout_width=".." and android:layout_height=".."to all the views:
<TextView android:id="#+id/storeText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right|bottom"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView android:id="#+id/distanceText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right|top"
android:textSize="16dp"
android:textColor="#545454"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
</LinearLayout>
<TextView
android:layout_height="fill_parent"
android:layout_width="0dp"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|center_vertical"
android:text=">"
android:textColor="#000000"
android:textSize="36dp"
android:textStyle="bold"
android:layout_marginRight="5dp" />
</LinearLayout>
every element you gave android_layout_weight you didn't give a width. If you gave this weight so the element takes a certain space you should give the layout
android:layout_width="0"
so it takes the weight as width
height and width are required tags for every element
you have missed some layout width and layout height attributes.
i have added in the all items.
Please use the below code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:weightSum="8"
android:layout_width="fill_parent"
android:layout_height="75dp">
<TextView android:id="#+id/priceText"
android:layout_weight="2"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:textStyle="bold"
android:textSize="22dp"
android:layout_width="wrap_content"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp" />
<LinearLayout
android:layout_weight="5"
android:layout_height="fill_parent"
android:weightSum="2"
android:layout_width="wrap_content"
android:orientation="vertical">
<TextView android:id="#+id/storeText"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="right|bottom"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView android:id="#+id/distanceText"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="right|top"
android:textSize="16dp"
android:textColor="#545454"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
</LinearLayout>
<TextView
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right|center_vertical"
android:text=">"
android:layout_width="fill_parent"
android:textColor="#000000"
android:textSize="36dp"
android:textStyle="bold"
android:layout_marginRight="5dp" />
</LinearLayout>
I don't know exactly what you want to achieve here by this layout but there are few mistake in your xml.
At various places width and height are missing. Consider adding those.
You are adding LinearLayout as parent tag but using RelativeLayout Tags like
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
do consider removing those.
Use properly combination of android:layout_weight="" and android:layout_height="" , android:layout_width=""
Comment if any clarification or help required