My definition XML is:
<CheckedTextView android:textSize="18.0dip"
android:text="#string/text"
android:textColor="#color/white"
android:id="#+id/test"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:checkMark="?android:attr/textCheckMark" />
Everything works fine but
the text always at the top left of the view and the checkbox is center vertical.
They are not at the same line.
How to align them.
add this line
android:gravity="center_vertical"
Related
I want to make drawable and text center in my EditText. The text is centered but the drawable is not. I want something like this:
http://i.imgur.com/cacxR2C.jpg?1
Please help. This is what I have done so far
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:gravity="center_horizontal"
android:drawableLeft="#drawable/lol2"
/>
When the user types in something in the EditText, the drawable should move itself to the left if the text is lenghty.
You can do something like this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#android:drawable/editbox_background"
>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Username"
android:background="#null"
android:gravity="center"
android:drawableLeft="#drawable/ic_launcher"
/>
</RelativeLayout>
This worked for me:
<EditText
android:id="#+id/searchET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="75dp"
android:paddingEnd="75dp"
android:inputType="text"
android:singleLine="true"
android:gravity="center"
android:hint=" Username"
android:drawableStart="#drawable/your_icon"
android:background="#android:drawable/editbox_background"/>
The kicker here is that you wrap_content for the width, align the text however, center the view however you'd like, then add padding to each end of the edit text.
This shoves the drawable to the start of your text but still lets you expand your edit text background.
instead of
android:drawableLeft="#drawable/lol2"
try using
android:drawableStart="#drawable/lol2"
Basically gravity attribute is used to apply changes of aligning the contents of lay out so you can put the gravity to center to align contents in center and center_vertical to to align contents on left side and gravity to center_horizontal to put contents in horizontal center. i.e
android:gravity="center"
Hi my ListView's list items layout is as below: Also attaching Image that shows the output of this layout . In the above output image we can see the text present in 2nd line over laps with right aligned TextView. I want 3 dots to be placed at the end of Text with out overlap.
<?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" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="16dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/sname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/name"
android:layout_below="#+id/name"
android:layout_marginTop="15dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/abbr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/sname"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
Can anyone help me in solving this issue ?
Thanks in Adavnce
Just add these layout attributes for your TextView
android:ellipsize="end"
android:maxLines="1"
This tells android you want your textview to be ellipsized at the end (add the 3 dots to the end of the text) and that you don't want your text to wrap to the next line (by setting the max lines).
The only thing you would need to then is make sure your TextViews don't overlap (the cri... portion). There are a number of ways to do this.
Move your abbr TextView to above your other TextViews and add android:layout_toLeftOf="#id/abbr" to your non-abbr TextViews
Redo your layout in general to make sure there is no overlap, using LinearLayouts would help achieve this with the benefit of things like weight.
Dynamically setting your widths once you know your window size.
I have following xml code:
It seems like the textview reflects to the 10 dp padding however the checkbox on the right side does not. The textview and checkbox are not aligned with each other. Anyone know why the checkbox is not conforming to the 10 dp padding? And is there a way to align my textview and checkbox?
<CheckedTextView
android:id="#+id/nearMeCheckedTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:clickable="true"
android:paddingTop="10dp" />
See this example... work for me
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/checkedTextViewInterest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="12dp"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
/>
try like this
<CheckedTextView
android:id="#+id/nearMeCheckedTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:clickable="true"
android:padding="10dp"
android:gravity="center_vertical" />
this is my layout
<HorizontalScrollView
android:layout_width="175dp"
android:layout_height="match_parent"
android:scrollbarFadeDuration="5">
<TextView
android:id="#+id/documentName"
android:layout_width="175dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:scrollHorizontally="true"
android:selectAllOnFocus="true"
android:singleLine="true"
android:text="Untitled Document123456789"
android:textColor="#ffffff"
android:textSize="20dp" />
</HorizontalScrollView>
Case 1: When i use text view alone, it shows Untitled Document... (...)denoting some text is hidden but i didn't get the horozontal scroll. Then i surround text view with horizontal scroll, i got the scroll but not the dotted text denoting some text is hidden
Please correct my layout if am missing anything.
Add this to your textview
android:ellipsize="start"
Instead of start you can have other values: end, middle ... You can look up at http://developer.android.com/reference/android/widget/TextView.html#attr_android:ellipsize
I have to draw two textviews such that when one text view ends, the other textview begins at the pervious ones left edge. I have to do this programatically as the text in each may vary.
How do I get the x co-ordinate of the left edge of the first textview and how do I set the right edge of the second textview to match the left edge of the first one.
Any help is appreciated.
Edit:
here is my layout
<TextView android:gravity="center_vertical|left"
android:textColor="#000000" android:textSize="10dip" android:id="#+id/updateorder"
android:layout_marginTop="50dip" android:layout_alignParentRight="true"
android:text="x" style="#style/compactview" android:background="#drawable/ornage"
android:paddingLeft="5dip" android:layout_marginRight="73dip"></TextView>
<TextView style="#style/compactview" android:id="#+id/neworder"
android:textColor="#000000" android:background="#drawable/red1"
android:layout_alignBottom="#id/updateorder" android:text="x"
android:textSize="10dip" android:gravity="center"
android:layout_toRightOf="#id/updateorder"></TextView>
no need to do this programaticaly ..
Just Define The two layout as below.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/relativeLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:layout_height="wrap_content" android:text="TextView1"
android:id="#+id/textView1"
android:layout_width="wrap_content"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView2"
android:id="#+id/textView2" android:layout_width="wrap_content"
android:layout_toRightOf="#+id/textView1"
></TextView>
</RelativeLayout>
You can achieve this thing using code as well
But clearly no need to get any exact position for a view.
Look on RelativeLayout documentation and layout_toLeftOf, layout_toRightOf attributes. You can find sample usage in this tutorial. Whats more if you set layout_width and layout_height to wrap_content you don't have to do anything programatically.