How to properly use the Space class in Android? - android

I have the need to use some Views as sort of place holders, but to not show anything. Its purpose is to make the TextView's that do show content to resize and share the available space horizontally. It is not necessary to go into detail, but what I am wondering is if I can use the Space class to accomplish this? I have seen it used in a GridLayout blog post, but other than that, there really isn't much on its many possible uses. The doc says its a light implementation of a View, which out of anything, would be the best way to accomplish what I need since it wont be too memory intensive. Is it only intended for GridLayout? There really isn't much info on it online so I was hoping someone could shed some light on the matter.
Just to elaborate a little of why I need to use the Space class, I have, say a LinearLayout. In that LinearLayout could be any number of TextViews horizontally. Say I want to resize it horizontally with a layout gravity, but not actually have another View actually show, just used to simulate that the size of the actually TextView with the content resizes correctly.
I appreciate any help!

The Space class was designed to include empty spaces in general purpose layouts and is very lightweight which makes sure that it doesn't add any overheads. Just put it in your layout like you would any other View. It's not specifically designed for any particular container. You can use it with a LinearLayout, a GridLayout, or anything else. Just don't expect it to display anything (not even a background).

if you want to give the space between layout .this is the way to use space. if you remove margin it will not appear.
hope that helps.
<Space
android:layout_width="match_content"
android:layout_height="wrap_content"
android:layout_margin="2sp" />

Related

How can I overlap TextViews?

I've just started an android development course and we had an assignment. I should create a simple birthday card app. That was not a problem until I started looking around and saw this picture.
I know 2 ways to achieve this. First, child TextViews in LinearLayout which might not allow to stack them in that sort of leaning/analog fashion. Second, and possible the simplest way I can think of, is to crop the text part and use it as an ImageView on top of the background.
I'm trying to challenge myself to create those bubbles using the code and I was wondering if somebody could help me do it.
Thanks!
If you want to recreate the stack of words on the right, you cannot use a LinearLayout. The LinearLayout won't allow you to overlap the TextViews. You'll have to use a RelativeLayout or ConstraintLayout. Each TextView should have a background image for the color and speckle design, you'll control how big the background is with TextView's padding and margin attributes. Finally you can tilt / rotate each TextView with the rotate attribute.
Don't get too ambitious with your early homework assignments, you wouldn't want to get frustrated and lose interest!

Android FrameLayout best solution

i have simple LinearLayout as container and i'd like to show severals FrameLayouts inside. It should looks like below but id but it needs to be dynamically. The point is that number of framelayout that i will need, will be return from sql response. I found some similar questions but i need to treat my framelayouts as surfaces (with elevation, margin...). When i run app it should looks like below example. Maybe somebody know best method to achieve this.
Look at the RecyclerView. You can add the children as CardView, you can control elevation and stuff.
PS: Next time you should research a bit. I bet you could find the answer faster than waiting for someone to give it to you

Accurately placing text in activity

As part of the android app I've been asked to write, there is a 'contact us' activity. This activity is supposed to have the company logo at the top, then various contact points (accounts payable, HR, etc) on the left (one on each 'line') with the corresponding number aligned on the right.
I've spent quite a few hours on attempting to use different layouts and placing them in the XML but it looks terrible.
What approach is best to solve this? It needs to look reasonable on both phones and tablets.
TIA
See Table Layout. From the way you're describing your problem, Table Layout seems to be an apt solution. You can even design your layout with Relative Layout as the base. However, you might have to use attributes such as android:layout_alignParentLeft="true", android:layout_alignParentRight="true" and others.

Problems with android GridView

I am trying to display 2 columns of text in a GridView in android. I create a TextView for each cell of the grid. Everything seems to work well until the TextView tries to wrap the text to a second (or more) line. When this happens, sometimes the second line of text overwrites the next cell, rather than causing the cell to expand to fit the text. All I have to do to get the text to display properly is click one of the cells in the grid. This seems to cause the grid to repaint and then everything gets displayed properly. I have tried any number of things to fix this problem but nothing seems to help.
Is there some property that I have to set on the TextView or the GridView to allow the cells to expand to fit the text? Or is this just a glitch in GridView that I have to live with?
BTW, setting android:singleLine="true" prevents the word wrap and solves the problem but it isn't an ideal solution because I really don't want the text to be truncated.
At a quick glance, I'm afraid you might have to do a work-around. I know it seems like a glitch, but it may be more ideal to continue to have your views start a consistent location instead of constantly having them shift based on content. I know this is a pain for what you're trying to do, but keep in mind that this was designed for hopefully the best solution for any application. Anyway..
One workaround I would propose might be manually updating the beginning of the views that get written over. I know it's not exactly ideal, but you can figure out where to place it based on the properties of your view. This doesn't feel like a particularly elegant solution though, so I'll try to cook something better up and/or post sample code. Good Luck!

creating a custom image based layout on android

Is it possible to create a layout based on (background) images? For example, there is well know app called Appie that uses this picture as a homescreen:
I might be able to recreate the layout with a TableLayout, but this will be difficult to get it perfectly aligned with the buttons in the image. The default layout options make it very difficult, or maybe impossible, to allow for selection of the buttons on the image (especially when the buttons are in an arc-path).
Can anyone tell me how this is done?
I had some issues positioning a badge on the corner of a view. You can check my solved question:
Positioning a badge bubble on the left upper side of a button
About how it can be done. I would do it with a RelativeLayout and TableLayout as you mentioned, but to be completely sure, you can use apktool to see how the xml are done but it might be ilegal to do it.

Categories

Resources