Hey, I have a problem where parts of the Text in the TextView are out of the screen, Look at the picture:
I marked the problem in red squares..
xml:
<?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:layout_gravity="right"
android:background="#drawable/list"
android:padding="15px">
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right">
<TextView
android:id="#+id/TfseerTextView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="17px"
android:textColor="#000"
></TextView>
</LinearLayout>
</ScrollView>
</LinearLayout>
Is it possible to fix? Is there any work around? Thanks.
you should use 17sp instead of 17px for your textSize. sp stands for Scaled Pixel, it will result in your app appearing better / more consistent across a wide variety of devices with differing screen sizes and densities.
As for the problem you are having. Does it make any difference if you set the TextViews layout_width attribute to some value e.g. android:layout_width="200dip" It looks to me like your TextView thinks that it has more space to use then it actually does (could be related to the grey box type things you have for the background, but this is a pure guess) If you set it to some specific value and it starts to wrap the text properly on the next line. Then you just have to try a few different widths and find out how big you can make it to keep everything appearing like it should.
Related
I've got a weird gap in my Android layout. I've set the background colors of my views and layouts so that you can see what is where. The gray box in the middle is the gap. I've got a RelativeLayout overall (white background), with a toolbar at the top (seen in pink), then a LinearLayout which is everything else (seen in yellow). In that yellow layout I've got two children: detail information (seen in blue), and a ListView (seen in red). However, the gray area in the middle... I have no idea where that is coming from.
Here is my layout file (with some info clipped for readability):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
>
<RelativeLayout
android:id="#+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="44dp"
android:background="#drawable/toolbar_gradient"
android:layout_alignParentTop="true"
android:background="#f0f"
>
<Button style="#style/Button.Done" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/toolbar"
android:paddingTop="4dp"
android:weightSum="10"
android:orientation="vertical"
android:background="#ff0"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="3.5"
android:weightSum="9"
android:orientation="vertical"
android:background="#00f"
>
</LinearLayout>
<ListView
android:id="#+id/tableView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="6.5"
android:background="#f00" >
</ListView>
</LinearLayout>
</RelativeLayout>
What is happening here? What am I missing?
EDIT: It appears the layout xml may not be the problem. I've been working to reduce and reduce and reduce and find the real culprit. It's looking like my problem exists in the ListAdapter code. Will update more as I discover it.
Did you try removing the android:layout_alignParentBottom="true" line from the definition of your first LinearLayout?
Ok, so after what felt like endless iterations of removing things until it was fixed and adding things back in until it broke again to narrow down to the specific problem I have discovered my error. I narrowed the problem down to my styling on the layout of the cells inside the ListView above.
I created a script awhile back to help me generate many different style.xml copies for different layout sizes and such so that I can provide good font size or layout_height values for different devices and make them look right. However, due to an error in my styles template, the style.xml which was being generated with a line <item name="android:layout_height">dp</item>. The missing number before the dp caused whacky behavior.
sigh Well, THAT sucked. ;)
Padding issue?
Update Sample of the issue:-
(Why is there a gap above the word "Late")
Update 2
Others gave reported similar issues here:- http://code.google.com/p/android/issues/detail?id=22493
So it seems that a textview doesn't reduce in size once it's been bigger. Any ideas for workarounds for this? setting the height explicitly causes the text to be cropped as it's lower than it should be.
I have a layout as follows:-
<?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:padding="1dp"
android:orientation="vertical"
android:background="#color/Green">
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/datetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/DateCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:textStyle="bold"
android:background="#color/Red" />
</LinearLayout>
and it is populated into a this GridView to form a calendar:-
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="7"
android:verticalSpacing="2dp"
android:horizontalSpacing="2dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
The adapter used to populate the gridview with the items changes the text size of #+id/DateCode to fit the text to the width of the available space. it then invalidates the textview and forces a re-layout (I know this works as the bottom of the textview does come up to the bottom of the resized text).
The top of the text within DateCode seems to start at least halfway down the TextView (which is clear as a red box. I don't understand why the area is not shrunk to fit the text in.
I assume it's a padding issue or something I don't understand, but it doesn't seem to be the font padding given how big it is.
Any ideas why the textview is positioning the text so far down, and not wrapping it into a much smaller space?
Anthony
If you are using ADT in Eclipse, then use the Hierarchy Viewer perspective to inspect live Views. That way you can know for sure what is going on with the layout; but to me the two TextViews look suspicious (i.e. where is the other? is it empty?)
I have a dialog box that contains an EditText, a RatingBar and two Buttons. The rating bar layout_width has been told to wrap_content, but it spreads out the stars to fit nicely in the space the edit text and the buttons make with their layout parameters. This wouldn't be a problem, but I have told it to increment by half-stars. The selected star value is drawn in real-time by chopping the filled in image, allowing for ratings of whatever fraction of star you want, but it seems the spacing is being included, making my half-stars look like third or quarter stars (especially on lower dpi screens where they make the stars much smaller automatically), while whole stars look fine.
Edit: I've noticed that stars to the left show this symptom far less than stars to the right, in all cases. By which I mean, a half-star on the left may be only slightly off, but a half-star on the right will be the furthest out of all. This happens on all phones I've tested. End edit.
I don't have access to the phone it is most obvious on, but you can still see the effect here:
A picture of a dialog with three full stars, a half star that isn't filled enough, and an empty star http://img534.imageshack.us/img534/1071/device2x.png
The fourth star is not quite filled half way, and it only gets worse on some other phones.
This is my layout xml:
<?xml version="1.0" encoding="UTF-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:padding="10dp">
<EditText android:id="#+id/reviewWriteText"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:ems="13"/>
<RatingBar android:id="#+id/reviewStars"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:numStars="5" android:stepSize="0.5" />
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal">
<Button android:id="#+id/reviewWriteAccept" android:text="Accept"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" />
<Button android:id="#+id/reviewWriteCancel" android:text="Close"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Maybe you can add this to you manifest file
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="7"/>
Or you should change the padding of rating bar.
After searching for a few hours, I was unable to find the exact answer to my situation. I'm currently using a RelativeLayout and all I have is a background image and a button. The problem I'm having is placing the button in the exact location I want it to be (a little offset from the center).
My first attempt was to modify the layout_margins of the button. While this worked for the current emulator I was working with (3.7in WVGA), the positioning of the button was slightly/way off for a different screen size (such as 3.2in HVGA).
I then attempted to modify the padding of the parent layout but got the same issue. My XML looks like this:
<?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:paddingLeft="98dip" android:paddingBottom="68dip" android:background="#drawable/background">
<Button android:id="#+id/starttimer"
android:background="#drawable/button"
android:layout_width="wrap_content" android:clickable="true" android:layout_height="wrap_content" android:layout_alignParentBottom="true"/>
</RelativeLayout>
Please let me know if I'm completely off with my approach. It seems like an extremely simple problem, and I'm bummed out that it's taken me so long to try to get it. Thanks for any help!
I take it that you want to center the button on the bottom of the parent with a little offset, try layout_centerHorizontal then add your preferred margin.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="98dip" android:paddingBottom="68dip" android:background="#drawable/background">
<Button android:id="#+id/starttimer"
android:background="#drawable/button"
android:layout_width="wrap_content" android:clickable="true" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android_marginLeft="5dp"/>
</RelativeLayout>
Absolute Layout is used for absolute positions of the control.
I've got a small clipping problem that I haven't been able to solve using an EditText view in a TableRow. Whatever I try, the EditText view is either clipped (attached screenshot), or, if I set shrinkColumns to either 0 or 1, the label text disappears (and the EditText view takes up the whole width). The layout is as follows:
<?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" android:padding="10dip">
<TableLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TableRow android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:paddingRight="10dip" android:layout_column="1"
android:text="Label Text" />
<EditText android:text="Very long text that makes the text view go on clipping frenzy"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
</LinearLayout>
I've tried it on a 2.2 emulator running at QVGA and HVGA, a HTC Hero on 2.1 and the Wildfire on 2.1 as well. I've also played around with the clipToPadding attribute which doesn't seem to help in my case. The same issue appears if I set the hint attribute with a long text and leave the text value empty.
As I am doing nothing particularly complex, I suspect a simple error on my side. Any ideas, hints or suggestions are highly appreciated.
Cheers!
Set android:shrinkColumns="1" on your TableLayout, and remove android:layout_column="1" from the TextView.
Add android:layout_weight="1", to your EditText, It took a while to resolve it..........
But don't know the reason for it.......