xml centered textview to much to left - android

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>

Related

how to set one linear layout below another linear layout in android

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation=""
android:layout_marginTop="40dp" >
<LinearLayout
android:id="#+id/imagecontainlayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:background="#drawable/round_bg"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:singleLine="true"
android:text="Status:"
android:textColor="#0060a4"
android:textSize="15dp" />
<TextView
android:id="#+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3.5"
android:textColor="#0060a4"
android:textSize="15dp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="20dip"
android:layout_height="20dip"
android:layout_weight=".75" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="295dp"
android:layout_height="44dp"
android:background="#drawable/round_bg"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:singleLine="true"
android:text="Status:"
android:textColor="#0060a4"
android:textSize="15dp" />
<TextView
android:id="#+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3.5"
android:textColor="#0060a4"
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>
Here is my Xml am trying to set imagecontainlayout linear layout to another linear layout containing another linear layout with some gap but i dont know where am doing mistake in my code my current screen is coming like this .
my current screen is coming like this while i want there first layout below another layout with some gap please help me where am doing mistake.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/round_bg"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:singleLine="true"
android:text="Step:"
android:textColor="#0060a4"
android:textSize="15dp" />
<TextView
android:id="#+id/step"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3.5"
android:textColor="#0060a4"
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>
use this code it will Help u .

How to align image at extreme left of listitem?

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>

how to set textview with image in linearlayout

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>

Button in LinearLayout not displayed in Android

I have a button in linearlayout above the image. The image is displaying properly, but the linearlayout above the image is not displayed.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E9E0DB" >
<LinearLayout
android:id="#+id/editdialogstartedlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/profdialogphotoimageview"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="5dip" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Edit"
android:textColor="#000000" />
</LinearLayout>
<com.example.masonrytest.views.ScaleImageView
android:id="#+id/profdialogphotoimageview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<LinearLayout
android:id="#+id/textlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profdialogphotoimageview"
android:background="#ffffff"
android:orientation="vertical"
android:padding="5dip" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/profdialogphotoimageview"
android:text="There Is Nothing Negative In Total Exploitation Of Natural Resources. What Say?"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="normal" />
<LinearLayout
android:id="#+id/dialog_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<ImageView
android:id="#+id/list_image"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignBottom="#id/text1"
android:src="#drawable/picture1" />
<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:padding="5dip"
android:text="By Andrew"
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="25dp"
android:src="#drawable/member" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
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:src="#drawable/udebate_fav" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp"
android:text="64"
android:textColor="#000000"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Any ideas or suggestions please?
Thanks.
Try it.
remove following property from LinearLayout.
android:layout_above="#+id/profdialogphotoimageview"
and put
android:layout_alignParentTop="true"
and also you need to put following property in "com.example.masonrytest.views.ScaleImageView"
android:layout_below="#+id/editdialogstartedlayout"
now you get the actual View which you need.
In your old code Your Button not view because of has fill-parent height so, it takes all size of the screen. and LinearLayout above of this layout that's why its gone above of the screen.
Your root level (the RelativeLayout) has children that all have fill_parent/match_parent. This means that all items are going to fill the available space. You will only see the last one (#+id/textlayout). Think about what you are trying to achieve with your layout.
If you use Eclipse, there is also a GUI you can test with.
Give id to main layout here RelativeLayout android:id="#+id/main"
and add
android:layout_below="#+id/main" to LinearLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E9E0DB" >
<LinearLayout
android:id="#+id/editdialogstartedlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="5dip"
android:layout_alignParentTop="true" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Edit"
android:textColor="#000000" />
</LinearLayout>
<com.example.masonrytest.views.ScaleImageView
android:id="#+id/profdialogphotoimageview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editdialogstartedlayout" />
<LinearLayout
android:id="#+id/textlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profdialogphotoimageview"
android:background="#ffffff"
android:orientation="vertical"
android:padding="5dip" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="There Is Nothing Negative In Total Exploitation Of Natural Resources. What Say?"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="normal" />
<LinearLayout
android:id="#+id/dialog_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<ImageView
android:id="#+id/list_image"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignBottom="#id/text1"
android:src="#drawable/picture1" />
<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:padding="5dip"
android:text="By Andrew"
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="25dp"
android:src="#drawable/member" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
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:src="#drawable/udebate_fav" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp"
android:text="64"
android:textColor="#000000"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
in the element com.example.masonrytest.views.ScaleImageView try adding the following line:
android:layout_toEndOf="#id/editdialogstartedlayout"

android how to add separator in headerlayout?

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.

Categories

Resources