How can I overlap TextViews? - android

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!

Related

Animate view breaking in half crookedly

I am trying to make an animation with a layout which contains a background and some text (TextViews) inside it. The animation should make the whole layout crack in the middle and then move slightly like a paper tearing. So not along a straight line but a random zig-zag pattern along the middle of the layout from top to bottom.
I've been trying to find something like this so can I get an idea how to do this but have not been able to so far. Does anyone know how something like this can be done on Android?
TIA
You can try Brokenview Or ExplosionField.
Brokenview(https://github.com/zhanyongsheng/BrokenView).
ExplosionField(https://github.com/tyrantgit/ExplosionField).
Have you tried with this example? In the blog you have an explanation of how to achieve this behavior.
The idea behind is basically:
Save your Activity's screen as a bitmap.
Split it into two parts.
Animate the bitmaps outwards.

Replacing a View in Android onClick

I'm still kind of new to android. I'm writing a Tic Tac Toe game as a bit of practice. I'm trying to figure out how to replace views when I click a button. I have 9 buttons in a GridView. When a user clicks one, I want that to change to a non-clickable TextView and back to Button when a user click's the reset Button at the bottom of the screen.. I use a flag to keep track of player's turn so it'll know whether or not place an x or o. Is this even possible or am I stretching here?
You'll soon find that there are really not that many things that are stretching it for Android.
This is certainly possible. For each grid in your GridView, put in two elements - the Button, and the TextView. Change the visibility of each. In other words, you don't actually replace one with the other - you just hide one, and show the other.
So you'd have two items like this:
<Button ... android:visibility="invisible"/>
<TextView ... android:visibility="visibile"/>
And have both of these match_parent, so that they fill each grid and are basically both on top of each other.
To change the visibility in the code:
button1.setVisibility(View.INVISIBLE);
textView1.setVisibility(View.VISIBLE);
I'm trying to give you as little actual code as possible so you play with this and write it yourself, but this should definitely put you in the right direction. Let me know if you need more guidance though.
You can do it two different ways
You can put both a button and a textview in each grid and interchange their visibility when you click on the button. For this, you can set the button and textview properties from the xml layout and you dont have to do much programatically
You can use a button alone and just change the look by changing the background drawable at runtime. Then you can make it unclickable by disabling it or changing its focusable property to false
You can even use an imageview and just change the drawable src and disable it on user click. Android is quite flexible and this is not even a stretch. If you give a little more detail of the specifics you want to achieve, I could advise which solution will be best fit

How to properly use the Space class in 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" />

Android horizontal scroll programmatically

In Android, I want to create a particular control which may require to set the location of a component by fixed coordinates.
This is what I want to do. These screenshot are taken from a swing application of mine. I want to clone the buttons on top and their behaviour, into an android application. Basically if there are too many buttons in the menubar, left and/or right arrows appear, and clicking on them will scroll horizontally to access the hidden buttons.
I need to be able to set the coordinates of an horizontal linear layout inside another one, and even to set negative coordinates in order to scroll on the right.
I'm doing this using a null layout in swing. Can I achieve this with Android ?
I'm not sure if an HorizontalScrollView can do this. Could someone point out a good tutorial or something related to what I'd like to do.
I think a HorizontalScrollView can achieve what you intend to do with your Menu Bar. You don't need these "scroll" Buttons, because a user can swipe the menu.
You can nest LinearLayouts together, however you want. if you want to control their flow try to apply margins to them. You can set fixed Coordinates in an AbsoluteLayout, too.
Consider using a gallery? If not gallery, then a child or cousin of it. As far as I know, there is no ViewParent that will allow what your are shooting for.
Hope that helped ~Aedon

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