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
Related
I want to apply ScrollView to my entire screen. But scrollview can host only one direct child.
I have tried this:
<?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="#E9E0DB"
android:fillViewport="true"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/dialogcreatemainlayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:background="#drawable/votes_bg"
android:orientation="vertical"
android:padding="5dp" >
<LinearLayout
android:id="#+id/dialogimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="3dp" >
<ImageView
android:id="#+id/dialog_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/dialog_image" />
<ImageView
android:id="#+id/profimage"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:src="#drawable/member_80" />
<TextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#id/profimage"
android:text="By Hermoine - 2 days ago on Politics"
android:textColor="#040404"
android:textSize="12dp"
android:textStyle="normal"
android:typeface="sans" />
</LinearLayout>
<LinearLayout
android:id="#+id/pub_arc_rem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/dialogimage"
android:orientation="horizontal"
android:weightSum="3" >
<Button
android:id="#+id/btnPublish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Publish"
android:textSize="12dp"
android:textStyle="normal" />
<Button
android:id="#+id/btnArchive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Archive"
android:textSize="12dp"
android:textStyle="normal" />
<Button
android:id="#+id/btnRemove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Remove"
android:textSize="12dp"
android:textStyle="normal" />
</LinearLayout>
<TextView
android:id="#+id/dialog_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/pub_arc_rem"
android:layout_marginTop="10dp"
android:text="There Is Nothing Negative In Total Exploitation Of Natural Resources. What Say?"
android:textColor="#343434"
android:textSize="12dp" />
<TextView
android:id="#+id/dialog_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/dialog_title"
android:layout_marginTop="10dp"
android:text="I don't think you have to believe one or the other. I have personally met christian's who simply think the big bang is how god created the universe. I have also met atheist who believe that we don't have the ability to know how the universe began. I have."
android:textColor="#343434"
android:textSize="12dp" />
<View
android:id="#+id/topformline"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_below="#+id/thumbnail"
android:layout_marginBottom="5dp"
android:layout_marginTop="6dp"
android:background="#android:color/darker_gray"
android:gravity="center" />
<LinearLayout
android:id="#+id/dialog_det"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/list_image"
android:layout_toRightOf="#+id/list_image"
android:layout_weight="5"
android:padding="5dip"
android:text="Last Active: 6 days ago"
android:textColor="#000000"
android:textSize="10dp"
android:textStyle="normal" />
<ImageView
android:id="#+id/list_image"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:src="#drawable/member" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:padding="5dip"
android:text="8"
android:textColor="#000000"
android:textSize="10dp"
android:textStyle="normal" />
<ImageView
android:id="#+id/list_image"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:src="#drawable/udebate_fav" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:padding="5dp"
android:text="64"
android:textColor="#000000"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/mod_friend"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/dialogcreatemainlayout"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="2" >
<Button
android:id="#+id/btnAssignModerator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Assign Moderator"
android:textSize="12dp"
android:textStyle="normal" />
<Button
android:id="#+id/btnInviteFriends"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Invite Friends"
android:textSize="12dp"
android:textStyle="normal" />
</LinearLayout>
</ScrollView>
Can anyone please guide me?
Thanks.
Wrap the content inside a Contanier. One from FrameLayour, LinearLayout, RelativeLayout
<?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="#E9E0DB"
android:fillViewport="true"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- your components -->
</LinearLayout>
</ScrollView>
Here is how its done:
<?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="#E9E0DB"
android:fillViewport="true"
android:orientation="vertical" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/dialogcreatemainlayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:background="#drawable/votes_bg"
android:orientation="vertical"
android:padding="5dp" >
<LinearLayout
android:id="#+id/dialogimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="3dp" >
<ImageView
android:id="#+id/dialog_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/dialog_image" />
<ImageView
android:id="#+id/profimage"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:src="#drawable/member_80" />
<TextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#id/profimage"
android:text="By Hermoine - 2 days ago on Politics"
android:textColor="#040404"
android:textSize="12dp"
android:textStyle="normal"
android:typeface="sans" />
</LinearLayout>
<LinearLayout
android:id="#+id/pub_arc_rem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/dialogimage"
android:orientation="horizontal"
android:weightSum="3" >
<Button
android:id="#+id/btnPublish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Publish"
android:textSize="12dp"
android:textStyle="normal" />
<Button
android:id="#+id/btnArchive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Archive"
android:textSize="12dp"
android:textStyle="normal" />
<Button
android:id="#+id/btnRemove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Remove"
android:textSize="12dp"
android:textStyle="normal" />
</LinearLayout>
<TextView
android:id="#+id/dialog_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/pub_arc_rem"
android:layout_marginTop="10dp"
android:text="There Is Nothing Negative In Total Exploitation Of Natural Resources. What Say?"
android:textColor="#343434"
android:textSize="12dp" />
<TextView
android:id="#+id/dialog_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/dialog_title"
android:layout_marginTop="10dp"
android:text="I don't think you have to believe one or the other. I have personally met christian's who simply think the big bang is how god created the universe. I have also met atheist who believe that we don't have the ability to know how the universe began. I have."
android:textColor="#343434"
android:textSize="12dp" />
<View
android:id="#+id/topformline"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_below="#+id/thumbnail"
android:layout_marginBottom="5dp"
android:layout_marginTop="6dp"
android:background="#android:color/darker_gray"
android:gravity="center" />
<LinearLayout
android:id="#+id/dialog_det"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/list_image"
android:layout_toRightOf="#+id/list_image"
android:layout_weight="5"
android:padding="5dip"
android:text="Last Active: 6 days ago"
android:textColor="#000000"
android:textSize="10dp"
android:textStyle="normal" />
<ImageView
android:id="#+id/list_image"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:src="#drawable/member" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:padding="5dip"
android:text="8"
android:textColor="#000000"
android:textSize="10dp"
android:textStyle="normal" />
<ImageView
android:id="#+id/list_image"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:src="#drawable/udebate_fav" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:padding="5dp"
android:text="64"
android:textColor="#000000"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/mod_friend"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/dialogcreatemainlayout"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="2" >
<Button
android:id="#+id/btnAssignModerator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Assign Moderator"
android:textSize="12dp"
android:textStyle="normal" />
<Button
android:id="#+id/btnInviteFriends"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Invite Friends"
android:textSize="12dp"
android:textStyle="normal" />
</LinearLayout>
</LinearLayout>
As you can see the ScrollView must have only one child.
just add vertical linearLyout after scrollview declaration and close the linearLayout before the scrolview tag is closed
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.
I have a problem in aligning an button and textView. I already have an textView and button in xml and i want another set of those, just below them.
But i am not able to add it. Please have a look at it.
Here is the xml,
<?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:animateLayoutChanges="true"
android:background="#FFFFFF">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top">
<com.aavishkaar.quikies.widget.TypedfacedTextViewxmlns:your_namespace="http://schemas.android.com/apk/res/com.aavishkaar.quickies"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Click Here"
android:id="#+id/textView"
android:layout_weight="0.6"
android:textSize="24sp"
android:textColor="#android:color/black"
android:gravity="center|left"
android:layout_marginLeft="15dp"
your_namespace:typeface="Roboto-Regular.ttf" />
<Button style="?android:attr/buttonStyleSmall"
android:id="#+id/blue0"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="OFF"
android:layout_weight="0.2"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/switch_bg_holo_light" />
<Button style="?android:attr/buttonStyleSmall"
android:id="#+id/blue1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="ON"
android:layout_weight="0.2"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:background="#drawable/switch_thumb_activated_holo_light"/>
</LinearLayout>
</LinearLayout>
Try this code just change orientation in your first linear layout by default linear layout orientation is horizontal
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="#FFFFFF"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top">
<com.aavishkaar.quikies.widget.TypedfacedTextView
xmlns:your_namespace="http://schemas.android.com/apk/res/com.aavishkaar.quickies"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Click Here"
android:id="#+id/textView"
android:layout_weight="0.6"
android:textSize="24sp"
android:textColor="#android:color/black"
android:gravity="center|left"
android:layout_marginLeft="15dp"
your_namespace:typeface="Roboto-Regular.ttf"
/>
<Button
style="?android:attr/buttonStyleSmall"
android:id="#+id/blue0"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="OFF"
android:layout_weight="0.2"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/switch_bg_holo_light"
/>
<Button
style="?android:attr/buttonStyleSmall"
android:id="#+id/blue1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="ON"
android:layout_weight="0.2"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:background="#drawable/switch_thumb_activated_holo_light"
/>
</LinearLayout>
<com.aavishkaar.quikies.widget.TypedfacedTextView
xmlns:your_namespace="http://schemas.android.com/apk/res/com.aavishkaar.quickies"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Click Here"
android:id="#+id/textView"
android:layout_weight="0.6"
android:textSize="24sp"
android:textColor="#android:color/black"
android:gravity="center|left"
android:layout_marginLeft="15dp"
your_namespace:typeface="Roboto-Regular.ttf"
/>
<Button
style="?android:attr/buttonStyleSmall"
android:id="#+id/blue0"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="OFF"
android:layout_weight="0.2"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/switch_bg_holo_light"
/>
<Button
style="?android:attr/buttonStyleSmall"
android:id="#+id/blue1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="ON"
android:layout_weight="0.2"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:background="#drawable/switch_thumb_activated_holo_light"
/>
</LinearLayout>
</LinearLayout>
Add
android:orientation="vertical" in first Linear Layour.
Add
android:orientation="horizontal" in Second Linear Layour.
I hope this will work , if not ignore this answer .
I'm Not very Good at this.
I have relative layout and inside it there are two linear layouts
the program works without the first linear layout. can any one explain why ?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bngp" >
<TextView
android:id="#+id/Cart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:gravity="center_horizontal"
android:paddingTop="10dp"
android:text="Cart"
android:textColor="#FFFFFF"
android:textSize="25sp"
android:textStyle="bold" />
// this is the linear layout causes error
<LinearLayout
android:id="#+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/Cart"
android:orientation="horizontal" >
<TextView
android:id="#+id/Product"
android:layout_height="wrap_content"
android:layout_weight="6"
android:text="Product"
android:textColor="#000000" />
<TextView
android:id="#+id/Quantity"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:text="Quantity"
android:textColor="#000000" />
<TextView
android:id="#+id/Price"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="Price"
android:textColor="#000000" />
<TextView
android:id="#+id/Value"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="Value"
android:textColor="#000000" />
</LinearLayout>
// end of linear layout
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/textView1"
android:layout_below="#id/table" />
<TextView
android:id="#id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linear"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:text="Total Value: "
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/Final_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/linear"
android:layout_toRightOf="#id/textView1"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:textColor="#FFFFFF" />
<LinearLayout
android:id="#id/linear"
style="#android:style/ButtonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Confirm" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Clear" />
</LinearLayout>
</RelativeLayout>
Check your layout now. I have edited some lines. use #+id instead of #id. You must know the difference between #id , #+id and #android:id.
ie,
"#android:id" which means you are referencing an item in Android namespace.
"#id" means you have defined ids in your application itself,
eg:-
===========================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="TextView1" type="id"/>
</resources>
in this case you have defined a textview id in your resources. Now you can use ,
<TextView
android:id="#id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
===========================================================
"#+id" means you are created a view (textview , layouts , etc..) in your layout and you wanted to add the id to R.java.
Check your layout now,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bngp" >
<TextView
android:id="#+id/Cart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:gravity="center_horizontal"
android:paddingTop="10dp"
android:text="Cart"
android:textColor="#FFFFFF"
android:textSize="25sp"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/Cart"
android:orientation="horizontal" >
<TextView
android:id="#+id/Product"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="6"
android:text="Product"
android:textColor="#000000" />
<TextView
android:id="#+id/Quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:text="Quantity"
android:textColor="#000000" />
<TextView
android:id="#+id/Price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="Price"
android:textColor="#000000" />
<TextView
android:id="#+id/Value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="Value"
android:textColor="#000000" />
</LinearLayout>
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/textView1"
android:layout_below="#+id/table" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linear"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:text="Total Value: "
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/Final_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linear"
android:layout_toRightOf="#+id/textView1"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:textColor="#FFFFFF" />
<LinearLayout
android:id="#+id/linear"
style="#android:style/ButtonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Confirm" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Clear" />
</LinearLayout>
</RelativeLayout>
For starters, instead of using #id/blah, always use #+id/blah (even if you are not defining the view). It doesn't hurt, and can prevent some really hard to track down errors.
For more details, please provide the error you are receiving.
I have this layout for my row in a listview... last image is not displayed... why?
<?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="70dip"
android:background="#android:color/black">
<ImageView
android:id="#+id/img"
android:layout_width="60dip"
android:layout_height="60dip"
android:layout_gravity="center"
android:layout_marginLeft="5dip"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="#+id/title"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginLeft="10dip"
android:layout_marginTop="1dip"/>
<TextView android:id="#+id/description"
android:typeface="sans"
android:textSize="12sp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:ellipsize="end"
android:layout_weight="0"
android:layout_marginLeft="10dip"/>
<TextView android:id="#+id/variable"
android:textSize="12sp"
android:textColor="#FFFFFF"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:lines="1"
android:ellipsize="end"
android:layout_weight="0"
android:layout_marginLeft="10dip"/>
</LinearLayout>
<ImageView
android:id="#+id/img"
android:src="#drawable/disclosure"
android:layout_width="60dip"
android:layout_height="60dip"
android:layout_gravity="center"
android:layout_marginLeft="5dip"/>
</LinearLayout>
Thanks in advance,
regards
EDIT: Try using a relativelayout so you don't have to have a linearlayout in the middle. I also have a three columnish thing going on so it should be similar for you.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id ="#+id/container"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="62dp"
android:cacheColorHint="#ff000000"
android:background="#color/white"
android:clickable="true"
>
<ImageView
android:layout_height="60dp"
android:layout_width="60dp"
android:id="#+id/thumbnail"
android:layout_marginRight="10dp"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:layout_marginLeft="2dp"
android:layout_centerVertical="true"
android:scaleType="fitXY"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingRight="10dp"
android:layout_toRightOf="#id/thumbnail"
android:textSize="13dp"
android:textStyle="bold"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_alignTop = "#id/thumbnail"/>
<TextView
android:id="#+id/merchant"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingRight="10dp"
android:layout_toRightOf="#id/thumbnail"
android:textSize="12dp"
android:textStyle="normal"
android:textColor="#000000"
android:ellipsize="end"
android:focusable="true"
android:lines="1"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"/>
<TextView
android:id="#+id/distance"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="#id/merchant"
android:layout_toRightOf="#id/priceButton"
android:textColor="#color/black"
/>
<Button
android:id="#+id/priceButton"
android:layout_height="60dp"
android:layout_width="70dp"
android:textColor="#color/white"
android:textSize="14dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="2dp"
/>
</RelativeLayout>
With no screenshot I would imagine you just have too much data on the screen , use a scrollview to allow the user to scroll.
Also why is your root layout's height limited to 70? Why dont you use fill_parent or match_parent