This question already has an answer here:
How to align TextView around an ImageView?
(1 answer)
Closed 6 years ago.
I have TextView and custom view called StarRating.
There is code snippet:
<RelativeLayout
android:id="#+id/flowtextView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.app.views.StarRating
android:id="#+id/star_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/_2sdp"
android:text="by Legacy Reviewer, April 11, 2014 from Chicago IL"
android:textSize="12sp"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/star_rating" />
</RelativeLayout>
Actual Result:
Expected Result:
The problem is that TextView is not wrapping the StarRating...
How can I do that ?
This is not HTML. In standard TextView text is layouted within TextView boundaries (rectangle), so this is working as expected. You cannot make it work differently as these views won't work that way and if they overlap they do not know about this anyway.
Another way to do it is add extra spaces in the beginning of your text. it's a little tricky though.
let me know if you want more details.
Try using android:gravity="center".
<RelativeLayout
android:id="#+id/flowtextView"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
Related
This question already has answers here:
Making TextView scrollable on Android
(32 answers)
Closed 4 years ago.
Scrollbar is showing but not working or scrolling as shown in image below
XML:
<TextView
android:id="#+id/text_view_dialog_notes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:hint="#string/rv_notes_content"
android:padding="5dp"
android:scrollbars="vertical"
android:minLines="10"
android:maxLines="10"
android:textSize="17sp" />
Where is something wrong and how to fix it?
Using scrollbar on textView
you have to add this line in java
textView.setMovementMethod(new ScrollingMovementMethod());
make sure you add that to your code:
yourTextView.setMovementMethod(new ScrollingMovementMethod());
This question already has answers here:
Android EditText draw a divider line between its drawable and its text
(4 answers)
Closed 6 years ago.
I need an EditText exactly like this:
EditText with icon and vertical line
Is it possible doing this at Android XML file?
Maybe this code helps you
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edit_text_selector">
<EditText
android:id="#+id/input"
android:layout_marginLeft="-10dp"
android:layout_toRightOf="#+id/your_icon"
android:text=""
android:padding="10dp"
android:background=""
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!-- icon -->
<ImageView
android:padding="3dp"
android:id="#+id/icon"
android:src="#drawable/perm_group_personal_info"
android:layout_width="40dp"
android:layout_height="40dp" />
</RelativeLayout>
Yes.
Use FrameLayout / RelativeLayout.
either way you can position imageButton with the image as src and costume drawable that will have only 1 side line.
I have the following code snippet:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/collected_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/card_text_color"
android:textSize="#dimen/card_headline_textsize"
android:layout_marginBottom="#dimen/card_headline_marginBottom"
android:text="Foo" />
<ImageView
android:id="#+id/collected_item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxHeight="140dp"
android:background="#android:color/holo_red_dark"
android:adjustViewBounds="true"
android:layout_below="#id/collected_item_title"
android:layout_marginEnd="8dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/collected_item_image"
android:layout_below="#id/collected_item_title"
android:text="Foo"
android:textColor="#color/card_text_color" />
</RelativeLayout>
I like to have the ImageView on the left and the second TextView either on the right of this image or unter the image, dependent on the size of the image.
The image should grow, until it reaches a maximum height of 140dp.
How can I automatically wrap the text if the image get's too width?
Unfortunately I have no idea at the moment how to do it.
Yes I can do it programmatically, but I like to reach the goal only with xml.
The wrapping RelativeLayout doesn't have to be a RelativeLayout, if this behaviour is possible with an other layout.
It sounds like you need a FlowLayout. Android does not provide one out-of-the-box, but check out this answer. How can I do something like a FlowLayout in Android?
Thanks to the answer of chessdork, I found the flexbox layout of google.
It gets provided by the following git repository.
https://github.com/google/flexbox-layout
This question already has answers here:
Remove space between stacked TextViews
(9 answers)
Closed 8 years ago.
I have two vertical TextView elements in my app.
There is lot of space between TextViews, pading and layoutMargin are 0
Is there way to reduce this space?
EDIT
Here is my code:
.
.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="right"
android:paddingRight="10dp"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/text_size_extra_small"
android:textColor="#color/home_tab_text_normal"
android:text="Test1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/orange_text_color"
android:textSize="#dimen/text_size_large"
android:textStyle="bold"
android:text="Text2"/>
</LinearLayout>
.
.
Thnaks
android:includeFontPadding="false"
Negative Margins can be set by two methods -
1) by xml - set the "android:Layout_marginTop" field negative - which other people have already suggested above
2) by java (Programmatically) - set the "topMargin" field of LayoutParams to negative.
You can also refer to this
You can try by giving negative margin to any of the layout.
Like for the second tv you can give:-
android:layout_marginTop="-10dp"
or
for the first tv:-
android:layout_marginBottom="-10dp"
You might need to change the values as per your requirement
This question already has answers here:
android ellipsize multiline textview
(23 answers)
Closed 9 years ago.
How can I make a multiline TextView that truncates the text properly? My TextView is part of a TableRow, so its width is a weight. The following does not work. The result is simply truncated text without the ellipses. I'm using API 10 (Android 2.3.3).
<TextView
android:id="#+id/name_recipe"
android:layout_centerHorizontal="true"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:text="Fried pork with mushrooms and potatoes and cilantro"
android:ellipsize="end"
android:maxLines="2"
android:paddingLeft="10dp" />
Reducing the two lines to a single line with the following does work, but it's not ideal:
android:singleLine="true"
I don't like this for two reasons:
android:singleLine is deprecated
I'd much prefer to have the text be on two lines than one.
I've seen discussion about this like from here but I'm hoping a new solution has been found by now.
Try this, it's from my project and works on phone but unfortunately not on tablet emulator:
<TextView
android:id="#+id/myItem"
android:layout_gravity="bottom|center_vertical"
android:textSize="10sp"
android:maxLines="2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:ellipsize="end"
android:lines="2" />
Use lines="1" as all the other methods are deprecated. As well as set scrollHorizontally.
<TextView
android:id="#+id/myid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
android:layout_weight="1"
/>