How to place a TextView behind another TextView? - android

I want to put a TextView overlapping another TextView in android studio, how should I do it?
Im using fontawesome as text and I want to put some text on top of the icon.
Also I didnt find any question regarding this.
Im not an expert in android studio, so sorry if im missing something.

Simply wrap your TextViews in either <FrameLayout> or <RelativeLayout>. Note the order matters here and the one you want on top should be the last one in your view group.
<FrameLayout>
<TextView "bottom one">
<TextView "top one">
</FrameLayout>

When you place both TextView to a RelativeLayout, the last defined one covers the first one.. so the first TextView appears behind the second TextView ..is it usable in your case?

Related

Add un text onto an image programmatically using Kotlin

I have a image "myXmlImage" in my .xml file
In the .kt file, I want to paste another "newImage" image as well as a little text "newText".
myXmlImage.setImageDrawable(newImage.drawable)
myXmlImage.imageMatrix = newImage.imageMatrix
So far it has been working very well and the new image is in place.
I'm completely stuck on how to paste the little "newText" into it
Any ideas will be greatly appreciated, thanks in advance.
Perhaps there's more than what you've described here. But if those are really your only specifications, then what you're asking for is really easy.
I'm assuming that your xml file has a root of ConstraintLayout. If it doesn't, then you're going to either want to change it or at least wrap your ImageView inside of a ConstraintLayout.
Use the layout editor to place a TextView inside of your ImageView (NOT AS A CHILD; when I say "inside", I mean spacially inside). If you haven't used the layout editor very much, it might take you a couple of tries to place the TextView inside. Don't just drag it into the ImageView as if it were a child. Drag it and drop it under the ImageView inside of the ConstraintLayout and then use little circles on the sides to attach it to the sides of the ImageView. Don't forget to set the text of the TextView as "".
(I'm not actually sure if this step is necessary because I don't know what the default background of a TextView is, but I do it out of habit.)When you're done placing that TextView inside of the ImageView, go the code of your xml file and use android:background="#00FFFFFF" (or maybe somewhere in your project you have either a transparent background drawable or a transparent #color that you can reference by name).
I'm sure you know the rest. Just give that TextView an Id like newtext and inside of your activity retrieve the view: newText:TextView=findViewById(R.id.newtext). And then set the text: newText.text="new text".

how to give margins between two text view as shown in image

My designer has given me the layout spec. as shown in image, so i have to give a exact 20dp gap between first TextView(Verification Code Resent) and second TextView(Please check your text message...) but their is always a default padding for TextView that increase the gap between these two TextViews, i want to know is it possible to give exact 20dp margin between these textview ,if not does my desiner need to make some changes in layout spec, i'm confused please help me..
You can use android:includeFontPadding="false" in your XML for the TextViews.
As an alternative, you can set setIncludeFontPadding (false) on the TextView in your Java code.

Android textview wrap around textview

Is it possible to wrap a textview around a textview, where the 2nd textview would wrap to the next line under the first textview?
For example:
<This is one textview> <This is
another textview>
I have tried using android:layout_weight="1" and relative layouts, however, they dont produce this effect.
No. If you're looking to format the two bits of text differently, consider using spans within one TextView.
This will be helpful to you. You can get same effect with HTML in text view
How to display HTML in TextView?
This is impossible because the "another textview" would have a non-rectangular widget area then.

Best way to program buttons/images

I am designing something that will have a homepage close to the Google+ android app.
I'm having trouble figuring out the best way to do this? Should I create a button with text and set the background as the image? Should I create an image with the text already programmed in the actual picture or should I program the text and picture to be buttons.
Any suggestions from you guys on past projects?
You can use a Button with text to whatever you like and then place the image for that button above the text (using android:drawableTop)like so:
<Button
android:id="#+id/imageButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Photos"
android:drawableTop="#drawable/button_image" />
replacing buttton_image with your actual image. If you want the image in a different position (i.e. below text etc) use:
android:drawableLeft
android:drawableRight
android:drawableBottom
This would be how I would and do do it...
Since I am a newbie in android development I may be wrong but I suggest why not use a Grid View with each grid item haaving a textview and imageview.
My suggest to layout:
If you want to try something new in Android 4.0 , you can try GridLayout to layout , it can reduce the complicate of the nested layout , check out the blog about GridLayout:
http://android-developers.blogspot.com/2011/11/new-layout-widgets-space-and-gridlayout.html
You should write Buttons this way: http://developer.android.com/resources/articles/layout-tricks-merge.html
I normally use RelativeLayout but this is not important.
Write a class myClass extends RelativeLayout and inflate the XML with
LayoutInflater.from(context).inflate(R.layout.myCustomLayout, this, true);
I think this is best practice by Google.
use a regular button and set the android:drawableTop="#drawable/icon_...." value
Having the text burnt into you image is most certainly not the way to go.
One option for you is a GridView. You could also do this through a combination of Image button and scrollview. In my opinion, GridView is best and involves the least amount of code with most flexibility.
Remember that you can replace the button's background image with a state list drawable.

Scrollable TextView in Android Widget

I would like to create an android widget with a scrollable textview.
The solutions given to this question
Making TextView scrollable on Android
cannot be applied because it is a widget:
1.
This
findViewById(R.id.textview).setMovementMethod(new MovementMethod());
does not work, since findViewById is not available in AppWidgetProvider but only in Activity.
2.Putting a ScrollView around the TextView also does not work, because I get an
InflateException:
android.view.InflateException: Binary XML file line #23: Error inflating class ScrollView
Can anybody give me a hint, how to make a TextView in a Widget scrollable?
I solved this problem by putting the text view inside ListView with single node, which is supported in App widget.
http://developer.android.com/guide/topics/appwidgets/index.html#collections
It looks like this is not possible.
More on this can be found here: http://code.google.com/p/android/issues/detail?id=9580
and here:
How to make a scrollable app widget?
So, probably it is possible to do make appwidgets scrollable in the HTC sense environment but not for normal android environments.
A way around this is to add buttons that go up and down in a list.
I have been working on this with two buttons which increment and decrement through an array. Just having trouble accessing the global variables. Did you make any headway on this?
Another solution is:
Add to textview any web link - for example: www.google.com.
Setting text value with HtmlCompat.fromHtml method:
textView.setText(HtmlCompat.fromHtml("some text" + "\nwww.google.com", HtmlCompat.FROM_HTML_MODE_COMPACT));
After that vertical scrollbar is appeared.
But it's not elegant and full solution. It's temporary workaround maybe...
The complete full solutiion is bat-el-g 's answer - with adding ListView.
Current marked solution (which just tell: "it's not possible") - is wrong.
In mainactivity.java:
after code text view:
TextView txt = (TextView) findViewById(R.id.textView id);
Enter this code:
txt.setMovementMethod(new ScrollingMovementMethod());
and you will be ok.

Categories

Resources