Even when gravity is set to top the text has some padding between it and view's border. I need to text to completely touch the border.
Bellow you can see the gap I'm trying to get rid of.
And here is the layout used:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/someView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Here is some text"
android:textSize="30dp"
android:gravity="top" />
</LinearLayout>
Try to create 9.patch line and set it to your TextView: android:drawableTop="#drawable/your_line".
Then set android:drawablePadding="-10dp"
This trick must work perfectly.
Try this on TextView in your xml file :
android:includeFontPadding="false"
--
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/someView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Here is some text"
android:textSize="30dp"
android:includeFontPadding="false"
android:gravity="top" />
</LinearLayout>
In xml try,
android:paddingTop="-5dp"
Negative paddings always seem to work for me.
Set the height manually instead of wrapping the content.
The linear layout is the item with the padding. You need to modify that element as well to remove the space.
Related
my Android TextView xml is very simple like below, I used style ScrollView but it won't show scrollbar, even when the text is exceeding the bottom and there is no way for me to see what's beyond. How to enable the scrollbar please?
I think "match_parent" has issue but don't know how to fix. Thanks!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff">
<TextView
android:id="#+id/textResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/buttonRecord"
android:layout_marginTop="16dp"
android:background="#drawable/back"
android:editable="true"
android:height="150dp"
android:text=""
android:enabled="false"
android:scrollbars="vertical"
style="#android:style/Widget.ScrollView"
android:layout_alignRight="#+id/buttonRecord"
android:layout_alignEnd="#+id/buttonRecord"
android:layout_alignLeft="#+id/buttonRecord"
android:layout_alignStart="#+id/buttonRecord" />
</RelativeLayout>
If you want the content to scroll, perhaps try giving it a fixed height? Right now the height is set to wrap_content due to layout_height. I don't think you should be using android:height at all
If you want a fixed height TextView to scroll vertically with scrollbar,
define your XML layout file:
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:text="#string/text_string" />
define your Java class file:
TextView tv = (TextView) findViewById(R.id.textView);
tv.setMovementMethod(new ScrollingMovementMethod());
I have an ImageView and TextView. I want to place the TextView below the image view but with the middle of the TextView aligned with the middle of the ImageView (along the horizontal axis). If the text in the TextView changes to something much larger or smaller, the middle of the text always needs to remain aligned with the middle of the ImageView. Is this possible in xml?
Yes, you are simply looking to contain both elements in a vertical LinearLayout which has android:gravity set to center_horizontal.
Something 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:gravity="center_horizontal"
android:orientation="vertical"
... >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
... />
</LinearLayout>
Because the TextView's width is wrap_content, setting its gravity shouldn't be necessary. I would do it just for safety (and additionally, I may set the width to match_parent as well).
You can make use of RealtiveLayout as follows..
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
... >
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
<TextView
android:layout_below="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
If you want your textview to be of single line only then add following properties to TextView
android:ellipsezed="end"
android:singleLine="true"
Use a given layout and add it to any of your existing layout you get result what your looking for ..
Hope this explanation works for you..
set TextView android:layout_width="fill_parent" and set android:gravity="center" in TextView.
I think it help you.
Thanks
I'm trying to create an expandable list where I can make the height of the group_row smaller, to use less screen space. When I change the layout_height of the LinearLayout, it changes the height to what I want it, but all of the labels of each TextView aren't displayed; they disappear. However, when it is wrap_content, the text appears. Any ideas how to fix?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="35dp">
<TextView android:id="#+id/childname
android:paddingLeft="0dp"
android:textSize="16dp"
android:textStyle="italic"
android:layout_width="150dp"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
Textview id should be android:id="#+id/childname"
I've created a custom spinner using my own ProjectSpinnerAdapter. I've also got another class which just inflates the layout but hasn't been implemented yet so is still using the standard spinner.
I can't seem to get my custom spinner to align the same way as the standard spinner.
I'm also having problems when the length of the item is wider than the table cell as you can see below. Is there not a way to truncate the options if they are over a certain length ? - This doesn't seem like its the correct way to fix this but I can't directly set the width of the widget as this is controlled via the table layout.*
**Fixed, See update*
Screenshots
The standard spinner aligns perfectly with the Button it sits next to (they are both contained within the same TableRow)
layout
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1" >
<TableRow>
<Button
android:id="#+id/selectButton"
android:text="#string/show" />
<Spinner android:id="#+id/projectSpinner" />
</TableRow>
spinner_list_item.xml (Uses maxLength)
<?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"
>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/title_text_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:maxLength="15"
android:gravity="center"/>
</LinearLayout>
Update
The issue was the layout of the spinner item, in my custom layout spinner_list_item.xml I'd specified a layout all I needed was the textview
spinner_list_item.xml (Uses maxLength)
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/title_text_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:maxLength="15" />
If I may ask, why did you choose the TableLayout? I think the same could be achieved with a RelativeLayout and layout_toRightOf layout_below, etc. Or a LinearLayout with a weightSum and gravity each child having a layout_weight.
I'm not going to give you a solution that changes your entire layout though ;), but I tested this and this seems to work for me.
<TableRow>
<Button
android:id="#+id/selectButton"
android:maxLength="10"
android:text="sdadadasdfffffffffffffffffffffffff"/>
<Spinner
android:id="#+id/projectSpinner"
android:ellipsize="end"
android:lines="1"
android:scrollHorizontally="true" />
</TableRow>
Hopefully this works and it's a better way than setting a fixed string length
edit
I'm not sure why you're populating the spinner the way you are, but you can try:
<?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"
>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/title_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:maxLength="15"/>
</RelativeLayout>
android:gravity is wrong too, needs to be android:layout_gravity (but that's LinearLayout only
Last edit :D
try using the default layouts
view = vi.inflate(android.R.layout.spinner_list_item, null);
then
((TextView) view.findViewById(R.id.text1)).setText(title);
I'm trying to position an image below a TextView in a RelativeLayout but it doesn't work. when i set its position using android:layout_below. This is my xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#ccc"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/app_details_1"
android:text="#string/app_details_1"
android:textColor="#347"
android:gravity="center"
android:textSize="9pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:id="#+id/logo"
android:src="#drawable/secs"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#+id/appdetails_1" <!-- I'm setting it here -->
/>
</RelativeLayout>
Instead it just places the image at the top left of the screen. How do I position it? Is layout_below a wrong positioning code?
There's a mistake in your xml. Must be
android:layout_below="#id/app_details_1"
it should be ok, but first try to make sure the textView is positioned on top by using layout_alignParentTop="true" for the textView and see if it does the trick.