I'd like to write a widget of dimension 3x1 that contains three equal buttons without a space in between. Instead of buttons, any other kind of View would be ok, as long as pushing them is possible.
I'd like to "overlay" text over all the three buttons so the text is not wrapped within one of the buttons.
What I have tried so far is this:
<TextView
android:id="#+id/update"
style="#android:style/TextAppearance.Medium"
android:layout_width="69dp"
android:layout_height="64dp"
android:layout_gravity="center"
android:background="#drawable/att_rec_red"
android:gravity="center_horizontal|center_vertical"
android:text="ABCDEFG" >
</TextView>
<TextView
android:id="#+id/update2"
style="#android:style/TextAppearance.Medium"
android:layout_width="70dp"
android:layout_height="64dp"
android:layout_gravity="center"
android:background="#drawable/att_rec_green"
android:gravity="center_horizontal|center_vertical"
android:text="ABCDEFG" >
</TextView>
<TextView
android:id="#+id/update3"
style="#android:style/TextAppearance.Medium"
android:layout_width="70dp"
android:layout_height="64dp"
android:layout_gravity="center"
android:background="#drawable/att_rec_blue"
android:gravity="center_horizontal|center_vertical"
android:text="ABCDEFG" >
</TextView>
What I did not like are the explicit widths of the TextViews. I had to fine-tune these numbers so the three TextViews fit exactly into the space of the widget. Is there a better way to do this?
Next question:
I'd like to place ONE text into / over these three TextViews (spanning all of them), but (of course) the text is specific to a single TextView. I could place three different text messages in there, but not one that spans all of them.
Is there a way to "overlay" text and still have the buttons visible and active (they can be pushed)?
As an alternative: Is it possible to have just ONE TextView and distinguish where within the TextView a push happened? I did not find any example for this but as it is possible to detect where within a View a push event happened, is it possible to detect that within the context of a widget? The setting the notification is done per View:
remoteViews.setOnClickPendingIntent(R.id.update, pendingIntent);
Is there a way to evaluate the position in a View too?
Related
I have created a layout XML and called setCustomTabView in the right sequence and verified that it's pretty much as described here.
How can custom tab view be implemented using setCustomTabView method in SlidingTabColor sample?
I don't want an image. I only want to control the text size. I want the default on a small phone, but twice the size on a tablet. The default is very small on a tablet. The app is used outdoors and visibility and large buttons is important. I have two "buckets" so far. The following examples are for the default.
If I use this xml layout, I only see the text for the first tab, and no colorizer.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Default sized TextView for tab title.
This allows us to specify a larger one for tablets in layout-w720dp. -->
<TextView
android:id="#+id/tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="18dp"/>
</LinearLayout>
If I add the xml for an image and provide a source, it works. If I leave out the source, the result is the same as for a layout with only a TextView.
<TextView
android:id="#+id/tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="18dp"/>
<ImageView
android:layout_width="wrap_content"
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content" />
In one of my experiments I increased the text size (very large) and without an image I got all four tab titles.
How can I replicate the default tab titles with only a TextView?
(I had a working solution where I detected the metrics at run time and doubled the text size, but I want to control this through different layout subfolders.)
I see that the default tabView is a simple, instantiated TextView and tabTitleView is equated to it. If I could do a findViewByIdon the TextView within my layout I could do the same. But attempts to do that resulted in a null TextView - probably because a ViewGroup is not yet established. But if I use my layout the child already has a parent and can't be used in the tab strip's addView().
This worked.
<TextView
android:id="#+id/tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="12sp"
android:gravity="center_vertical|center_horizontal"
android:padding="16dp" />
Using the debugger (and looking at the source where the default tabView is created) I saw that gravity was 0x800033 for my TextView and 0x000011 for theirs. Changing the android:gravity and adding the same padding as the default fixed it. I think center would also work. It's an alias for vertical|horizontal (1<<4|1<<0).
I also called setAllCaps(true) on the tabTitleView for consistency.
I'm having a changeable text like in the screenshot, where the quantity changes according to plus and minus buttons.
What is the best to implement that on Android ?
Could I make use of Spannable text in this case ? Or do I implement that with
a vertical LinearLayout with a TextView then a separator view then another TextView that changes ?
If you want to make it your own way, look for click events on the plus and minus buttons, change an integer variable (say mQuantity) according to these click event (mQuantity++ or mQuantity-- respectively), and change the TextView content with mQuantityLabel.setText(mQuantity+"");. That extra +"" is to avoid setText looking for a probably non existing id inside strings.xml. You could just need to convert the int to String, but this suffices for this case.
However, and it may be more sensible to go for already established solutions for number increase/decrease such as NumberPicker (after API 11) or SimonVT's NumberPicker (backport of NumberPicker, if the minSdkVersion is prior to API 11).
Managed to achieve this layout, using LinearLayout.
It was straightforward I thought that it might need tricky layout technique, but turned out to be easy.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/quantity"
android:textAppearance="#android:style/TextAppearance.Medium" />
<View
android:layout_width="match_parent"
android:layout_height="2px"
android:background="#color/black" />
<TextView
android:id="#+id/quantity_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="01"
android:textAppearance="#android:style/TextAppearance.Medium" />
</LinearLayout>
I have a listview where each item has 2 images, one on the right and the other on the left. Between them there is a textview that is filled from data. If text is long then it can continue down but there is a lot of free space just as you can see in the image. I want to use this space also to display text. I have been looking around the web and I have seen things like this http://code.google.com/p/android-flowtextview/downloads/detail?name=FlowTextDemo.zip&can=2&q= but this is useless. I don't want to lose the control of the images because I need their click method. What is the best way to do it? I have thought that maybe I can put a textview between images and an other down and when the first is filled continue in the second one but how can I know how many letters can keep the first textview?
I don't understand why FlowTextView (that you linked to) won't work for you. It's derived from RelativeLayout and flows text around any child views. The child views can be your images, positioned as you normally would in a RelativeLayout. Their onClick methods should work just fine.
<com.pagesuite.flowtext.FlowTextView
android:id="#+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/the_text >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:onClick="onTopLeftClick"
android:src="#drawable/top_left_image" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:onClick="onTopRightClick"
android:src="#drawable/top_right_image" />
</com.pagesuite.flowtext.FlowTextView>
You will need to set the text in code, or else extend FlowTextView and define your own custom attribute(s) to do it from xml.
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
I am trying to port my WP7 app to android.
Does anyone know how I can layout the text on a single button so that some text appears aligned left and other text appears aligned right? (See below). I need access to be able to dynamically change the percentage number on the right side using code but the text on the right is just static.
Anyone know the answer to this?
The image is here:
http://i.imgur.com/zW7YV.png
Yes you could make it two buttons.
Remove all padding and margin from between them.
Set the same background drawable.
And just ensure when the left is clicked it invokes the right's onPress method (so it looks as if they depress together).
Or wrap the buttons/imageviews/textviews in a layout and perform the onClick on that.
I would use a RelativeLayout for this.
<RelativeLayout
android:width="fill_parent"
android:height="wrap_content"
android:clickable="true"
android:background="#18a2e7"
android:padding="10dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Something" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_align_parentRight="true"
android:text="0%" />
</RelativeLayout>