Take a look at my layout
http://pastebin.com/6tQVm3Rk
My problem is that the textviews (named header1 to 5) are resizing its containers when a certain amount of letters are written into it, although there is still some space left.
What changes do I have to make that the layout stays in its original state independent from the amount of text located in the headers?
This might be because of this attribute.
android:inputType="textMultiLine"
If you want your textview to have only one line you can use android:singleline="true"
Add the attribute
android:maxLength="2"
to the textview. This way you can limit the number of characters.
I think its better to use Relative layout instead Linear layout in the XML so that objects in Relative layout are easy to manage dynamically, all you need to do is that put all those text views in the Relative layout and set these parameters:
layout align left:
layout align right:
And other solution which is not appropriate is that fix the size of text view then it will not expand.
And please see the Documentation for further details of Relative Layout.
Set the width and heigth of your textview to a fixed amount of dp. This will prevent the textview from streching beyond the width and height you declared. Like this:
android:layout_width="50dp"
android:layout_heigth="50dp"
For me the solution was to use
android:layout_width="0dp"
together with
android:maxLines="1"
Related
I have a chain in a ConstraintLayout which consists in a TextView, an ImageView and another TextView (doesn't need autosizing). I'd like them three to be vertically centered in the parent container (i.e. same distance to left/right).
I want the TextView to autosize so the text doesn't overflow. I can't use autosize with a layout_width set to wrap_content (nothing happens and the text doesn't resize). I can't set a fixed layout_width either since the extra space when the text isn't very long throws off the alignment.
Is there anyway to do this via XML or should I implement my own autosizing behavior?
This is a picture of what I'm trying to achieve (a center-aligned chain):
For TextView Auto-sizing, use android:layout_width="0dp".
But make sure you apply the ViewComponents Left/Start and Right/End Constraints.
This trick is basically used instead of android:layout_width="fill_parent" in ConstraintLayout.
Using this, you'll achieve Auto-sizing and it will consume only the space falling under the specified constraints and no over-lapping and no spilling-out.
I am developing for android. The app is designed in XML in Linear Layout. What I want to do is to leave some blank lines between the consecutive buttons/text to ensure some neatness in the GUI. Is it posible to do it in Linear Layout? Please help...
You should use margins to seperate different components in your layout. An example of how this would look in your XML is: android:layout_marginTop="12dp"
If you want to leave space outside the border of text/button and next view elements you can use android:layout_marginLeft, android:layout_marginRight, android:layout_marginTop and android:layout_marginBottom.
If you want to leave space between border of the text/button and actual content of the text/button you can use android:paddingLeft, android:paddingRight, android:paddingTop and android:paddingBottom.
For more info check out this question
how to increase the space between the elements in linearlayout in android?
I am trying to fit two EditTexts horizontally. What I am trying to accomplish is make the text keep scrolling right without the EditText extending in anyway when there is no more space in that specific EditText. This happens when the EditText is set to match_parent (width), but when I set an actually width or wrap_content, it breaks to the next line. Not the behavior I am hoping for. Any ideas?
If I understood your question correctly, you're saying you want the edit text to be a single line each? If so, have you tried using the xml attribute
android:singleLine
Or you can accomplish the same thing with:
setSingleLine() //called on the edit text
I just tested it out with 2 edit texts in a horizontal linear layout set to 100dp width each and I think it accomplishes the behavior you want.
You can try this:
Set both to fill_parent and layout_weight=1. This will align them side by side.
I'm adding a TextView to a parent LinearLayout RelativeLayout programmtically. There is enough space for the text to be displayed horizontally but for some reason the text is displayed vertically. Does anyone know what's going on here?
It's really hard to say what is the problem without looking at your XML and layout code. In my experience, sometimes it happens when the parent layout has height set as WRAP_CONTENT and the views inside it have wrong weight config, for example one has weight but WRAP_CONTENT and the other MATCH_PARENT (Sorry, I don't remember the case exactly). I suggest you check your LayoutParams carefully or set a fixed width and height for the TextView to see what is the problem.
You can also post your code here so we can have a look at it
I have a RelativeLayout defined in xml and I call the setContentView(R.layout.relativeLAyout) for displaying in Activity.
Now, if I want to resize this RelativeLayout then can it be done and if yes, then can someone let me know how?
The inner components can be resized relatively to the parent.
Is this actually possible?
Regards
Sunil
well if you use Eclipse, in the XML file, there at the bottom just switch to Graphical Layout.
and from there you can drag and drop payouts, Buttons etc :D
then in properties you can select add the pixels (200px ) on width/height
As to the inner components not resizing, make sure that both android:layout_width and and android:layout_height are set to fill_parent - then they should take up the space given to the parent.