I want to add a textview right at the end of another textview, ie not in next line, but where previous textview ends, in xml file. Just like:
| <TextView1><TextView2> |
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbb |
My xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
android:ellipsize="none"/>
<TextView
android:id="#+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="bbb" />
</LinearLayout>
but text "bbb" is not shown. Can anyone help?
Use following.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="none"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
/>
<TextView
android:id="#+id/date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="bbb" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
android:ellipsize="none"/>
<TextView
android:id="#+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="bbb" />
</LinearLayout>
use weight sum .....
I have provided both 50% space you can change as per your requirement.......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
android:ellipsize="none"
android:layout_weight=".5"/>
<TextView
android:id="#+id/date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="bbb"
android:layout_weight=".5" />
</LinearLayout>
as per requirement ......
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
android:ellipsize="none"
/>
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bbb"
android:layout_alignRight="#id/textView"
/>
</LinearLayout>
</HorizontalScrollView>
This is because you have provided android:ellipsize="none" as none and giving a very long text to textView.
just provide android:ellipsize="end" and you will be able to see second textView.
Use a RelativeLayout and have your "aaaa..." text view align to the left of the "bbb" textview. You can either remove maxLines or set it to some other value if you want multiple lines.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/date"
android:ellipsize="none"
android:maxLines="1"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="bbb" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="fill">
<TextView android:id="#+id/textView"
android:text="bbb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_alignParentRight="true" />
<TextView android:id="#+id/date"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/textView"
android:singleLine="true"
android:ellipsize="none" />
</RelativeLayout>
it's simple use one textView and inside your cod use append method and add some space before your second text :)
Related
How can make TextView with break line behaviour in layout ?. Please see image
Use the following 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:orientation="horizontal"
android:weightSum="1" >
<EditText
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center"
android:text="text" />
<EditText
android:id="#+id/rtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center"
android:text="text" />
</LinearLayout>
i have a Fragment with following Layout:
<?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="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:background="#ffffff"
android:id="#+id/dateItemRow"
>
<TextView
android:id="#+id/timeField"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textStyle="bold"
android:layout_marginTop="3dp"
android:paddingBottom="0dp"
android:textColor="#5d6265"
android:textSize="16sp" />
<LinearLayout
android:id="#+id/rowBackground"
android:layout_width="3dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#33b5e6"
>
<TextView
android:id="#+id/seperator"
android:layout_width="2dp"
android:layout_height="fill_parent"
android:textColor="#000000"
android:text=""
/>
</LinearLayout>
<CheckBox
android:id="#+id/mycheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:button="#drawable/custom_checkbox_design"
/>
</LinearLayout>
How you (hopefully) see this is a Layout where on the Left site is a Time Field then kind a Border to separate the TimeField from the CheckBox. What i'm looking for is to set all of them to Center.
Actual everything is on the Left Site.
All this is in a ListView what i have described like this:
<?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:background="#e8e8e8" >
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#e8e8e8" >
</ListView>
</LinearLayout>
I really have NO Idea how i can get this. THX for your HELP!!
Try adding
android:gravity="center"
to your outer LinearLayout.
Sorry if my question sounds simple but I'm working on a simple layout for my list item and my intention align to textviews one on each end of the layout. My attempts are as below but the texviews are right next to each other. Any ideas where I'm going wrong?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ll_finc_calctr_result_label">
<TextView
android:id="#+id/tv_finc_calctr_result_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_alignRight="#+id/ll_finc_calctr_result_label"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/ll_finc_calctr_result_label">
<TextView
android:id="#+id/tv_finc_calctr_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</LinearLayout>
</RelativeLayout>
Try this..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:id="#+id/tv_finc_calctr_result_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="text left" />
<TextView
android:id="#+id/tv_finc_calctr_result"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="text right" />
</LinearLayout>
Firstly, you need to remove the two properties of alignRight and toRightOf from the second linear layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ll_finc_calctr_result_label">
<TextView
android:id="#+id/tv_finc_calctr_result_label"
android:layout_width="wrap_content"
android:text="ss"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_alignParentRight="true" >
<TextView
android:id="#+id/tv_finc_calctr_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sse"
android:layout_gravity="center"/>
</LinearLayout>
</RelativeLayout>
Which will result in the second textview on right side.
And I would advise that you don't take two linear layout as both of them contain just a single textview:
Something like:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:id="#+id/tv_finc_calctr_result_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ss" />
<TextView
android:id="#+id/tv_finc_calctr_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="sse" />
</RelativeLayout>
Output:
The solution provided by Hariharan is excellent. Another option might be more useful if you need the textViews' width to actually be wrap_content (for instance if they have a background styling, etc.) You can achieve a more accurate behavior using a space:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:id="#+id/tv_finc_calctr_result_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<TextView
android:id="#+id/tv_finc_calctr_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
I've a two line listview with the following XML for the row:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip"
android:gravity="center_vertical"
>
<TextView
android:id="#+id/designation"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="2"
android:id="#+id/orderedValue"
android:gravity="bottom"
android:singleLine="true"
android:ellipsize="marquee"
/>
</LinearLayout>
what I want is to have the first row (designation) to be at the exact vertical center of the row, and the second row (orderedValue) just below it
I've been trying with several combinations of LinearLayout/Relative layout, gravity vs layout_gravity for the TextViews to no avail
Any help/pointers here?
I'd make a blank View above the first TextView which can share the same weight as the text below it.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip"
>
<View
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
/>
<TextView
android:id="#+id/designation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:id="#+id/orderedValue"
android:singleLine="true"
android:ellipsize="marquee"
/>
</LinearLayout>
If I were you I'll try to put designation TextView inside a LinearLayout and use android:layout_gravity to center it. I tried this in my activity and it centered the first TextView. However, I'm not sure if it will work in your list.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip"
android:gravity="center_vertical" >
<LinearLayout
android:id="#+id/layout"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/designation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="18sp"
android:textStyle="bold"
android:text="designation" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="2"
android:id="#+id/orderedValue"
android:gravity="bottom"
android:singleLine="true"
android:ellipsize="marquee"
android:text="orderedValue" />
</LinearLayout>
iTurki, thanks for the input, but I just solved it before reading your solution.
I switched to a relative layout and changed some parameters, most importantly adding: android:layout_centerVertical="true".
here is my final layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent"
android:padding="6dip"
>
<TextView
android:id="#+id/designation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="19sp"
android:layout_centerVertical="true"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/orderedValue"
android:singleLine="true"
android:layout_below="#id/designation"
android:paddingTop="6dip"
android:textColor="#33B5E5"
android:textSize="13sp"
/>
</RelativeLayout>
Thank you both for your interest!
Have somebody implemented ExpandableListView inside layout? I'm trying to do it and I have problems with height. I want to make it "wrap_content" in order to see fully expanded View when it is expanded. But unfortunately with "wrap_content" parameter I cannot achieve this result. Can somebody help?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/user"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_below="#+id/rl"
android:layout_toRightOf="#+id/user"
android:paddingLeft="3dp"
android:text="Top User"
android:textColor="#000000"
android:textSize="22dp" />
<ExpandableListView
android:id="#+id/elvMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/user"
android:layout_above="#+id/about" >
</ExpandableListView>
<TextView
android:id="#+id/about"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:text="Bottom About"
android:textColor="#6f6f6f"
android:textSize="24dp"
android:textStyle="bold" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Group row in ExpandableListView:
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="#+id/groupname"
xmlns:android="http://schemas.android.com/apk/res/android"
android:textStyle="bold"
android:textSize="20dp"
android:paddingLeft="40dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="#drawable/expanded_upper_selector"
android:gravity="center_vertical"/>
Child Row:
<?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="wrap_content"
android:background="#drawable/ingredients_selector">
<TextView android:id="#+id/ingredients_second_layer_text"
android:textStyle="bold"
android:textSize="20dp"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:textColor="#color/dark_orange"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"/>
Check out this link - http://about-android.blogspot.in/2010/04/steps-to-implement-expandablelistview.html
Here only one custom text is added.in similar way you can add second one.Try this and if any query you can feel free to ask.Hope this will help you.
Try your XML edited some-much:
Your_XYZ_Main_XML::
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#000000" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00ff00" >
<TextView
android:id="#+id/user"
android:layout_width="match_parent"
android:layout_height="100dp"
android:paddingLeft="3dp"
android:text="Top User"
android:textColor="#111111"
android:background="#eeeeee"
android:textSize="22dp" />
<ExpandableListView
android:id="#+id/elvMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ExpandableListView>
<TextView
android:id="#+id/about"
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="Bottom About"
android:textColor="#6f6f6f"
android:textSize="24dp"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Group_Row_XML ::
<?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:orientation="vertical" >
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/groupname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#159357" // YOUR_BACKGROUND
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingLeft="40dp"
android:text="Parent text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="20dp"
android:textStyle="bold" />
</RelativeLayout>
Child_Row_XML ::
<?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:orientation="vertical" >
<TextView android:id="#+id/ingredients_second_layer_text"
android:textStyle="bold"
android:textSize="20dp"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:textColor="#ff2211" // YOUR_COLOR
android:text="Child Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"/>
</RelativeLayout>