android reduce space between two vertical TextViews [duplicate] - android

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

Related

android :gap between two textview in relative layouts

Android: I want to have gap of 20 dp between two textview i am using relative view and have already used textview 2 should be below textview 1 , but i dont understand how to give more gap in between these 2 textviews
You can use padding or margin. I recommend margin.
<TextView
android:text="text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/your_id"
android:layout_margin="20dp" />
EDIT:
Thanks to #Gabe Sechan to amplify the answer. If you want margin only in one side, you can use the specific margin instruction of the side you want. Example:
Margin only on bottom
<TextView
android:text="text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/your_id"
android:layout_marginBottom="20dp" />
And the other sides
android:layout_marginTop, android:layout_marginLeft and android:layout_marginRight.

Android EditText with icon and vertical line [duplicate]

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.

Android textview wrap custom view [duplicate]

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>

What would be a way working with layout weight

I have tried this. I planned to do like this:
But it showing in this way:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvHiragana"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hiragana"
android:layout_weight="2"
android:textSize="22sp" />
<TextView
android:id="#+id/tvKanji"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kanji"
android:textColor="#color/redColor"
android:layout_weight="1"
android:textSize="20sp" />
</LinearLayout>
What should I do make it work correct in the terms of layout_weight? How to avoid making new lines in TextView?
What should I do make it work correct in the terms of layout_weight?
First, when using weight with a horizontal layout, your width should be 0dp. Similarly, if your layout is vertical then your height should be 0dp.
How to avoid making new lines in TextView?
use android:singleLine="true" if you want to
Constrains the text to a single horizontally scrolling line instead of letting it wrap onto multiple lines
TextView Docs
If this doesn't answer your question then please be a little more clear because its a bit confusing on what you're asking.

TableLayout with images and text

I would like to show an image in the left cell and text in the right cell of a tablerow.
My problem is that the text-view is floating outside the visible screen, so I can't see the whole text. The text should break at the visible right end of screen. I've tried to set a maxWidth with a pixel value but that doesn't work.
Can anyone offer a solution to my problem. Maybe there is a better layout option?
my layout-definition:
<TableRow>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="#55ff0000"
android:src="#drawable/bla"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/aboutblaImageText"
android:textSize="6pt"
android:textColor="#FFF"
android:maxWidth="100px"
/>
</TableRow>
Try setting the stretchColumns and shrinkColumns properties of the Table. It worked for me.
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0"
android:shrinkColumns="1">
I took the idea from the Jonathan Roth answer in this post.
Add android:shrinkColumns="1" property to your TableLayout.

Categories

Resources