I have a ListView where each objects in the list has the parameter:
android:layout_height="wrap_content"
However, this makes the objects hard to press. I don't want to increase the font size to achieve this. Instead, can I add a buffer to wrap_content?
I'd like to implement something like:
android:layout_height="wrap_content" + 10dp
How do I do this?
Thanks
Add some margin or padding to your views. Alternatively, embed a <View> element with fixed 10dip height.
you can use padding property so its automatically set height & width what you want...
android:padding="10dip"
you would have to do that programmatically most likely. Because that method wont work.
Not exact coding but along the lines:
View what_i_want_to_resize = (View)findViewById(R.id.myview);
View view_with_the_size = (View)findViewById(R.id.sizeview);
what_i_want_to_resize.setMinimumHeight(view_with_the_size.getMeasuredHeight() + 10);
Something along those lines. It is impossible to do it with XML.
You can also add padding to it.
android:padding="10dp"
That will make a padding or cushion between the views.
Try using android:layout_margin="10dip" or padding.
You have to give android:layout_height="50dp" or any figure directly
Related
I have a RecyclerView list where some items (text) are too long for the width allowed by the device. I can use android:ellipsize="end" to indicate that the text is truncated but I want to be able to show user the whole text. I can use android:scrollHorizontally="true" and then the text will scroll but there is no visual indication for the user that he needs to scroll it and the text just looks truncated. What would be the good UX for this case? Thanks.
1、you can edit your textView like this
xml
<TextView
...
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:text="......"/>
It will auto scrollHorizontal,Or you can use a autoFitTextView in you list item,auto fit textview.
You can add android:scrollbars="horizontal" to your recyclerview to show the scrollbar.
Turned out that the solution is to wrap the item in HorizontalScrollView and set android:layout_gravity="fill_horizontal". This allows for scrolling and there is a horizontal scroll bar for long items.
So, after many investigations, I've found the problem solution:
This happens due to MARGINS and PADDINGS (and maybe other offset parameters) inside your TextView and its parents. Just remove them and see the result.
I hope it helped new googlers!
PS:
If you want to save your offset parameters try to change the layout width parameter inside your TextView and its parents to wrap content (but somewhere also try 0dp or match parent), it also worked for me. So your UI will look exactly as you want!
Folks, I have the following layout: http://dpaste.com/hold/755261/
It has two seekbar widgets. Both are not showing. If I move them to the root linearlayout, they appear, otherwise not. I need them to be inside the first linearlayout. Anyone could help me how to achieve that?
It looks like you need to put the following in your third LinearLayout:
android:layout_weight="1"
Change the second LinearLayout height to wrap_content. If the content doesn't fit on the screen, then maybe you have to use a ScrollView.
I there a way to wrap_content on a specific element inside of a parent element? For instance, I have something like the following layout:
<RelativeLayout width:match height:wrap>
<ImageView width:match height:wrap scale:fitXY />
<LinearLayout width:wrap height:wrap>
</RelativeLayout>
The parent wrap constraint is very loose, but I want it to specifically use the matching width, but always match the height of the image view.
The problem here arises when I place this view in another RelativeLayout where each view is aligned above or below another in order to fill a potentially changing superview. LinearLayout didn't really seem to stretch things to fill, so I switched to Relative, but when I did, the view described above stretched vertically when I want it to still match the height of the image view.
Is there a good solution to this problem?
You could try putting the following (pseudocode) in the onResume() method:
if(myRelativeLayout.height > myImageView.height)
myRelativeLayout.setHeight(myImageView.height);
You need to make sure to call myRelativeLayout.measure() before you do this, so the system knows what the size of the Views will be.
Just an idea for you to try, let me know if it works :)
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"
I'm having trouble developing the UI for my first lame "game".
Here is a screenshot.
I'm using a LinearLayout that contains a TableLayout with TableRows. It seems so tedious and hard to control the position of elements.
For example, to get things to line up, I've inserted empty TextViews to "push" other elements into place.
I've also added padding to the buttons to get them to be the size I want.
Is there a better way of doing this?
Thanks!
You definitely want to be using a Relative Layout for this.
You would be able to specify where each button is in relation to other buttons.
Absolutely AVOID developing your UIs the way you are currently trying. The TextViews will be different sizes for different distributions of Android, and will likely only look right on the device you tested them for.
EDIT:
If you need empty space, use the XML attribute android:weightSum="x" in the parent view and android:layout_weight="y" in the child. This will make the child take up (y/x) of the space allotted to it in the layout_height and layout_width.
EDIT:
I think another good bit of advice for this would be to use individual layouts for things like your "direction" buttons. You'll be able to handle where they are on the screen as a group, instead of having to move each individually.
You should use RelativeLayout to solve this problem. I've gone through a similar problem once...
I didn't use the the Android's default buttons, for I had my own images for the pressed and unpressed behaviors...
Let suppose you want to place the east "button". You could use a function like:
public void addEastImageView(RelativeLayout myBackgroundLayout, ImageView center, ImageView east, int leftPadding, int topPadding, int rightPadding, int bottomPadding){
RelativeLayout.LayoutParams rightSide = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rightSide.addRule(RelativeLayout.RIGHT_OF, center.getId());
east.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
myBackgroundLayout.addView(east, rightSide);
}
The ImageView called "center" would be the one you called "i" in your image. The padding parameters would allow you to control the distance between the ImageViews. You can create functions like this one to add the "west", "south" and "north" buttons also: you just have to change the parameter "RelativeLayout.RIGHT_OF" to "RelativeLayout.LEFT_OF", "RelativeLayout.BELLOW" and "RelativeLayout.ABOVE" accordingly.
If you want some behavior for your ImageViews, you just have to set it in the setOnClickListener. You can then change your ImageView's "image" with setBackgroundResource, for example, and set the others logic behaviors you want.
Hope it helps :D
Use an AbsoluteLayout - it lets you state exactly where to put every element
http://mobiforge.com/designing/story/understanding-user-interface-android-part-1-layouts
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<Button
android:layout_width="188px"
android:layout_height="wrap_content"
android:text="Button"
android:layout_x="126px"
android:layout_y="361px"
/>
<Button
android:layout_width="113px"
android:layout_height="wrap_content"
android:text="Button"
android:layout_x="12px"
android:layout_y="361px"
/>