I'm having an issue in one of my activities with text being cut-off at the first letter.
The issue is, whenever navigating away from this activity to another (via the tabs at the top), and then going back to this activity, all of the text except the first letter in all of the textviews gets cut-off:
The funny thing is that every time I repeat this process (leaving the activity and going back), the text comes back, gets cut-off, comes back, gets cut off....repeating.
My table layout is defined as follows:
<TableLayout
android:id="#+id/statisticsMiddleTableLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/statisticsMiddleTextTitleLayout"
android:stretchColumns="1">
With all rows having the following structure:
<TableRow
android:id="#+id/tableRow1Statistics">
<!-- TitleRow -->
<TextView
android:id="#+id/statisticsTableR1CLText"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="#string/statisticsTableR1CLText"
android:textStyle="bold"
android:textColor="#FF6600"
android:paddingTop="0dip"
android:layout_margin="0dip"
android:gravity="center_horizontal"
android:layout_weight="1"/>
<TextView
android:id="#+id/statisticsTableR1CRText"
android:text="#string/statisticsTableR1CRText"
android:textStyle="bold"
android:textColor="#FFFF66"
android:gravity="center_horizontal"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:paddingTop="0dip"
android:layout_margin="0dip"
android:layout_weight="1"/>
</TableRow>
I have found that setting "android:layout_width" to something other than "0dip" for the textviews solves this problem and the text doesn't get cut-off, but then I can't get an equal width between the textviews. I'd have to rebuild the entire activity UI without a table, which I don't want to do.
The more interesting factor is that this does not happen on a real device (I only have one to test it on though) and I had never seen this bug before upgrading the android SDK tools to Revision 10.
So now I wonder, is this a bug in the SDK revision 10 tools, or should I rework the entire UI for this activity? Has anyone else experienced this issue with using "0dip" for the "layout_width" textview attribute inside of a table?
I would forget about the SDK tools and just worry about the emulator and devices. The majority of my layouts do not render correctly in the layout editor.
Related
In Android I am trying to do a RelativeLayout in which I want to use layout_above on something that is aligned with layout_alignBaseline, but find that this is not working correctly.
Note: I tested with API levels 14, 15, and am going to check in 19 (latest) as soon as I get that installed, with the same result. By the way, I'm referring to appearance in Eclipse layout editing GUI - I haven't tested on a real device, but I assume it's supposed to be consistent...
My real layout is complicated but I have reduced it to this simple example:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="A"/>
<TextView
android:id="#+id/b"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/a"
android:text="B"/>
<TextView
android:id="#+id/c"
android:layout_alignParentLeft="true"
android:layout_above="#id/b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C"/>
</RelativeLayout>
With this layout, I would expect to see the letter A at bottom right (yes), the letter B at bottom left (yes), and the letter C immediately above the letter B. In fact, the letter C does not appear - it seems to have been positioned off the top of the view.
If you replace the layout_alignBaseline on B with layout_alignTop or alignBottom, because in this example A has the same font size, this does not change the appearance of A and B at all - but now C appears in the correct place.
My basic question is, why does this not work when using the baseline alignment? Is this a bug or am I doing something wrong?
Notes:
Obviously in this simplified example there is no reason to use layout_alignBaseline, but it is necessary in cases where the font sizes are not the same.
This is not an urgent problem because I have come up with a less neat way to achieve a similar layout. But I'd like to know for future reference why it doesn't work.
I did look at the related questions but didn't spot the answer.
I'm using a horizontal LinearLayout to divide a rectangular block of the device's screen into 3 equal parts. This is accomplished using weights.
The purpose of this is putting 3 buttons side by side, a settings button, a help button, and a contact button. As per my knowledge, it should follow that the first button in the LinearLayout is on the left, the next is in the middle, and the last is on the right, due to the hierarchy rules of a LinearLayout.
This is what the Visual Editor also shows. But when I run the application (and I've tried on multiple devices), the contact button ends up on the left, the settings button ends up in the middle, and the help button ends up on the right.
I tried changing the hierarchical structure of the code (i.e. I placed the code for contact button above the code for settings button, etc.) but it didn't make any difference to the result.
The code for the LinearLayout is below:
<LinearLayout
android:id="#+id/icons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100">
<ImageButton
android:id="#+id/settings"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="33"
android:src="#drawable/settings" />
<ImageButton
android:id="#+id/help"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="33"
android:src="#drawable/help" />
<ImageButton
android:id="#+id/contact"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="33"
android:src="#drawable/contact" />
</LinearLayout>
There is nothing wrong in the XML. If the application is really using the above XML, then changing the ordering of the ImageButtons in the layout should indeed change the ordering on the screen.
Here's 2 things that come to mind:
There is a problem with your build/run process, and updated code changes are not reflect when you run your application. I suggest making a change to some obvious string resource and test if this is the problem. You should also do a clean build just in case.
You have multiple layout files with the same name (for example, one in layout/ and the other in layout-land/), and you're not changing the right one.
This is easily the weirdest problem I've ever faced.
So today, I created a new Android Project. The first layout xml had just a textview that has the following properties (its inside a relative layout):
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="124dp"
android:background="#80ffffff"
android:gravity="center_vertical"
android:text="Welcome"
android:textSize="48dp"
android:textStyle="bold" />
What I wanted was to have a textview that has text in its center. But the text STARTS from the center and goes out of screen towers the right side.
So I thought I must be doing something wrong. I went into one of my older projects (it was also open in eclipse). I opened an XML there, and shockingly, all the text there has also moved to the left (It starts from the center, rather than actually centering the text). It was fine yesterday. Here's the button:
<Button
android:id="#+id/gettingstarted"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/login"
android:layout_below="#+id/login"
android:layout_marginTop="10dp"
android:text="Getting Started"
android:textColor="#ffffff" />
I have no idea what happened. Why is the text no longer centered in buttons in all my projects? I'm in a really tough spot right now. Kindly help.
For your first problem try
android:gravity="center_vertical|center"
but for your text views in your all projects , it's a general question , maybe it's occured because of changing in your apps theme or projects styles
I am working with modified version of sample WeatherListWidget to get a better understanding of App Widgets. Things are fine - except when I try to replace the dark_widget_item and light_widget_item layout files with slightly more complex layout files. Here is original layout:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget_item"
android:layout_width="match_parent"
android:layout_height="46dp"
android:paddingLeft="25dp"
android:gravity="center_vertical"
android:background="#drawable/item_bg_light"
android:textColor="#e5e5e1"
android:textSize="24sp" />
I would like to be able to have multiple text lines. But:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget_item"
android:background="#drawable/item_bg"
android:layout_width="match_parent"
android:layout_height="46dp"
android:paddingLeft="25dp">
<TextView android:id="#+id/type_string"
android:textColor="#666666"
android:textSize="20sp" />
<TextView android:id="#+id/title_string"
android:textColor="#666666"
android:textSize="18sp" />
</LinearLayout>
fails.
In fact, it results in "Sorry! The application Launcher (process com.android.launcher) has stopped unexpectedly. Please try again. Force close".
Reinstating TextView widget_item.xml fixes this. I suspect that part of the problem is how I reference RemoteViews in WeatherWidgetService.getViewAt() - but I am getting very little help from DDMS or LogCat or anything else.
Thanks guys, I got the notification. (SO requires a username with length > 2, hence the dot)
Answer as per comment:
I don't see any layout_width and layout_height attributes for both of the TextViews in your LinearLayout - they are mandatory. Also, if you want the two TextViews to be above eachother, add android:orientation="vertical" to the LinearLayout. And just to the record, you can break a CharSequence to multiple lines in a single TextView by adding "\n" inbetween the different elements.
If you're going to include an image as well, then you're probably better off with a LinearLayout than a single TextView indeed, although you could potentially use the intrinsic drawable option of the latter. That could get a little messy though, especially if you're planning on using different styles for the different lines of text... Not impossible, but I'd stick with the LinearLayout. ;)
There are two numbers constantly displayed in my UI. I need the user to be able to specify those numbers. In a desktop app I simply use 2 spinbuttons, and can beat it (I guess). However, there are problems with this in Android (I am targeting Android 3-based tablets).
First of all, I've tried NumberPicker widget, but it simply does not show itself properly (I've asked a question about it, but no response so far).
Then I've tried some 3rd-party numberpicker implementations one cand find on the Web, but for various reason didn't like neither of them. Some of them are too large to fit the side panel I'm squeezing controls into, some are just ugly (and too small, probably), and all of them automatically grab input focus causing the keyboard to show every time I open this side panel.
There is another option - only show the uneditable label with a number on the panel, and show popup window with some numberpickers in it. Apart from me not knowing how to implement such a popup (just learning), how do I decorate the label so that the user understands he can tap it to edit?
Perhaps, there are better solutions for this problem? I took a look at some apps from Google Market, and they all seem to either use huge NumberPickers at the center of the screen (and I need as much of the screen as possible clear), or a popup with the same huge Numberpickers I don't particularly like.
Can you suggest anything else? Thanks in advance!
There are two different issues in your question:
For the number picker for eaxmple in my case I have created a simple tool. You can just put a button with the text "-" then a textview and then a button with "+". You put it in a linear layout and t can be vertical or horizontal. If you want it you can make it very small. For example here is what I have wrote but you can try playing with the options to see which is better for you.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:orientation="vertical" android:id="#+id/linearLayout1"
android:layout_width="wrap_content" android:layout_weight="1"
android:layout_height="wrap_content">
<Button android:id="#+id/button22" android:layout_gravity="center"
android:layout_weight="1" android:text="+" android:gravity="center"
android:layout_width="30dip" android:layout_height="30dip"></Button>
<Button android:id="#+id/button11"
android:layout_gravity="center"
android:layout_weight="1" android:text="-"
android:gravity="center" android:textAppearance="?android:attr/textAppearanceSmall" android:layout_height="30dip" android:layout_width="30dip"></Button>
</LinearLayout>
<LinearLayout android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1" android:orientation="vertical">
<Button android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="30dip"
android:text="0" android:id="#+id/quantidad"></Button>
</LinearLayout>
then you can add onClick listeners on the buttons and setup to increase or decrase the text displayed in the text view.
As for the keyboard well if you use that example you not need it but if you use an edittext then you can setup an option for the keyboard to be hidden in the manifest: you can see the option here http://developer.android.com/guide/topics/manifest/activity-element.html