How do i add a textview ontop of a picture - java

UPDATE: so i got the picture as a layout:http://gyazo.com/38a4c80dab36e15593a32f35951b9f7d
Now how do i make it so that i can put text on the picture. I want to make sure that the text doesnt go beyond the picture box. Thanks in advance!

Add a RelativeLayout where your picture is now. I suppose your picture has a fixed size (e.g. 60dp wide and 60dp high). Use that size for your RelativeLayout. Now add an ImageView as first child with both width and height set to match_parent. This ImageView will contain your picture. Add a TextView as second child, also with width and height set to match_parent. Now you have a TextView on top of an ImageView, both with the same size.

Related

Changing LinearLayout Height from top (default from bottom) in Android programmatically (Java)

I want to change the height of a LinearLayout and works everything OK, but I want height decreasing and increasing from the top (the defaults starts decreasing and increasing from the bottom).
Here is an example:
LinearLayout linearLayout = findById(R.id.layout);
LinearLayout.LayoutParameters layoutParams = (LinearLayout.LayoutParameters) linearLayout.getLayoutParams();
layoutParams.height = linearLayout.getHeight() - 1;
linearLayout.setLayoutParams(layoutParams);
This works OK. The only thing I wanna change is the direction of height change.
Thanks for the replay.
You can achieve this by binding(the bottom) of your linear layout inside a constraint layout,
Also is there a parent to your linear layout?, if so then it being unbound might be the reason
I achieved changing the direction with the setLayoutDirection(View.LAYOUT_DIRECTION_LOCALE) from teh ViewGroup class. Also had to change layout's gravity to bottom in the xml.
Thanks for contribute to my answer.

Horizontal LinearLayouts in Vertical LinearLayout, last line height not working,why?

I have a vertical linearlayout in my activity, and many dynamically added (in code, not xml) horizontal linearlayouts in it. There are several textview in the horizontal linearlayouts.
I set the height of the textviews by command line, and the height of every single textviews are the same.
Everything works fine, except the final horizontal linearlayout: its height is compressed to let the text in its textviews to show in the vertical center. (almost half of its height should be displayed out of the cell phone screen, which is the exact effect i want)
why its height automatically shrink? How can i get the effect i want?

How do I keep my splash screen's background from stretching?

How do I go about setting the background for a splash screen that does not stretch, and maintains a density-independent size? Here's a visual of what I'm trying to go for:
I have a large image file (1000x1000px) of the background. I want the background to maintain its density-independent size, with the excess just not visible, so that it will be displayed correctly on various screen sizes. I also want the center of the image anchored to the center of the screen. (the image above is just a mockup, the focal point should be at the center of the image)
How do I do this?
You have a link here in stackoverflow that might help.
You can use an ImageView as your background (otherwise backgrounds of any view will just stretch).
And use it as the background of your ImageView. Your ImageView can then have the layout_width and the layout_height as wrap_content.
Then, set the ScaleType as android:scaleType="centerCrop".
Note that this ImageView has to be the first element of your layout. Otherwise it will just hide everything in your layout.

Android Custom View: MATCH_PARENT with OnDaw don't work

I'm new to Android but i have a simple problem.
I have a vertical linear layout, if i place here a normal button, and give it the MATCH_PARENT flag for the width and the height, the button will fill all the space. All ok.
Now i have a my simple custom view (a class that extends View) and i overrided the OnDraw method for draw a cross in the middle of the view. For draw the cross i need to get the width and the height of the control, if in the UI Layout editor of eclipse i set a fixed width and height, it works correcly (i see a preview of the cross directly in Eclipse) but if i extend the View to the borders i got only WARP_CONTENT (With button i get MATCH_PARENT), no problem, i change it in the XML, but LayoutParams width and height will return 0!! (I see the error directly in the preview of eclipse!) Why?
I tried to set manualy the width and the height in the OnWindowFocusChanged method to wait but it give me always 0.
The problem is that the view actualy have the rights dimensions but when i call the getLayoutParams().width it give me 0, so i see a white rectangle in the right position (white background of the view), but the cross is drawed on the upper-left corner!
Sorry for my bad english.
Thank you.
Mauro.
i think u need to set this parameter for your view.
android:layout_alignTop
or something related to this.i guess

Two overlapping ImageViews in Android

In a ViewGroup I want to put two ImageViews overlapping: The imageview A have a transparent background and some drawing across the image, the imageview B.
I want both them to be at the same place and have the same size (but can't fix their size in the XML because if the image at ivB changes the ivA should resize to match the new size.
Since the ivA source image does not change I tried ivA.getWidth() and ivA.getHeight() for setting the ivB size but their value are 0,0 in the onCreate() method.
Is there some "easy" way of doing this?
Override the ImageView and in onLayout() you can get proper width or height after calling super.onLayout(). Try setting values in the place.
Try getting the dimensions in onWindowFocusChangedListener.
An easier way would be putting the ImageViews in a FrameLayout (which is built to put Views on top of the other), and resize the FrameLayout instead.

Categories