My first (old) Android app (Suspension Calculator) is showing a problem I cannot find a solution for: the spinner control on some spinners is showing transparent lines in unwanted places. The pattern is this: every other spinner is having this problem, starting with the first spinner control. So while spinners 2, 4, 6, ... have no unwanted lines, spinners 1, 3, 5, ... have them.
The following image (link below) shows the spinner in selected state first, and in unselected state after the red separator. In selected state, the transparent line is at baseline height for the entire control except some places where the button text can be. It's a little different in unselected state.
I cannot provide an image directly:
[...] as a spam prevention mechanism, new
users aren't allowed to post images.
But I can give you a link:
Screenshot that illustrated the graphical spinner problem
The XML file under res/layout looks like this:
<ScrollView ...>
<TableLayout ...>
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/units"
android:gravity="center_vertical"
android:paddingRight="5dp"
/>
<Spinner
android:id="#+id/unit_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
/>
</TableRow>
...
</TableLayout>
</ScrollView>
I see this problem at least since Froyo (Android 2.2). In earlier versions (at least Android 1.6), it wasn't there. It's not there in the Graphical Layout editor in Eclipse, but I see it running the application on the phone and in the emulator - that's at least consistent and hints to a problem I'm causing by not doing things right ;-).
Actually I can reproduce this behavior on Android 2.3. Not possible on Android 2.2 and lower.
It' doesn't matter if you place the Spinner in a TableLayout or RelativeLayout. Same problem there..
Only solution to get ride of the lines was to put a 1px-View between the spinner:
<Spinner android:layout_height="wrap_content" android:id="#+id/spinnerDriver"
android:layout_width="match_parent" android:layout_below="#id/driverDesc" />
<View android:id="#+id/helper" android:layout_height="1px"
android:layout_width="match_parent" android:layout_below="#id/spinnerDriver" />
<Spinner android:layout_height="wrap_content" android:id="#+id/spinnerDriver1"
android:layout_width="match_parent" android:layout_below="#id/helper" />
This is actually a very, very, very... ugly solution but it works for me...
Related
I use latest Android Studio and SDK. In preview & real device i see this:
My code:
<?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"
tools:context="com.myappname.view.AboutActivity">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listViewAbout" />
</RelativeLayout>
How i make subtitle text color is gray? Like this:
I'm going out on a limb and assume that you're using the row layout simple_list_item_2.xml (based on the screenshot) which gives you two rows. The problem, if you may call it that, is that depending on the SDK version, the styling for this layout has changed.
On SDK 23, it looks like this:
However, on say SDK 19, it looks like this:
Why?
To understand this we first need to take a look at the xml that generates the rows from simple_list_item_2.xml, you'll see it's a pretty simple layout that uses the now deprecated view TwoLineListItem but that's just a plus on why to use your custom layout.
<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/listPreferredItemHeight"
android:mode="twoLine"
android:paddingStart="?attr/listPreferredItemPaddingStart"
android:paddingEnd="?attr/listPreferredItemPaddingEnd">
<TextView android:id="#id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textAppearance="?attr/textAppearanceListItem" />
<TextView android:id="#id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/text1"
android:layout_alignStart="#id/text1"
android:textAppearance="?attr/textAppearanceListItemSecondary" />
</TwoLineListItem>
The reason is because of the way the style textAppearanceListItemSecondary is resolved in each SDK version. The style is what gives the text the size, the color, etc. The evolution of the interface in Android has given birth to a huge ecosystem of themes and relying on the default styling will result in inconsistencies like the one you stumbled upon.
What to do about it?
You should use your own layout for this to allow for uniform styling across versions. To do so, please refer to any of the multiple questions covering this matter. But in short it just means creating a layout file, call it for example custom_row.xml and having the layout look exactly as you please. This also gives you total control over placement of the items, extra Views that you may need, and overhead in terms of coding is minimal compared to the SimpleAdapter or ArrayAdapter that perhaps you were using.
Note
You should consider moving your code towards RecyclerView instead of ListView if you haven't already.
You can set Textview property
android:textColor="#color/grey"
in you Adapter layout to change colour of your sub item
Hope this will help
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 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. ;)
I am trying to display a text box using textView.I am adding some data in it during runtime. I just want it to display a box of size 23 lines.
Code am using is this.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/twittertext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fadingEdge="vertical"
android:maxLines="23"
android:minLines="23"
android:background="#drawable/dropshadow"
android:scrollbars="vertical"
android:text="Getting data on your slow n/w..."
android:textColor="#ffffff"
/>
</ScrollView>
</LinearLayout>
Now when i see this in emulator it's coming perfectly (Android 2.2) but when i test the same code in a real device (Wildfire 2.2.1) the box is not coming for 23 lines. Rather it just show a 5 line box. Am able to scroll but looks like the
:minLine
is not working.
Please help me.
Ok. I dont have a answer for it. But this is how i solved, just in case someone else want it.
I have used the screen pixels and then calculated the pixels i need for the view. Then added the same as
android:layout_height
property and it worked for me.
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.