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".
Related
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.
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?
I have this fragment layout where some content needs to be animated (like showing/hiding input field).
Now I found out I could manage this by using a fancy animation (by using <item name="android:animateLayoutChanges">true</item> on a linear layout).
The problem I have here is that I need to add al content programmatically..
For example
LinearLayout timesheetsWrapper = (LinearLayout)inflatedView.findViewById(R.id.new_timesheet_wrapper);
EditText timeSheetName = new EditText(getContext());
timeSheetName.setHint("Name");
timesheetsWrapper.addView(timeSheetName);
Now image I need to add like 10 GUI components and style each one of them programmatically, which is a bit of a hassle to me.
Is there a way that I could add a partial layout .xml file into the 'wrapper'?
For instance:
LinearLayout partialLayout = ...??
timesheetsWrapper.addView(partialLayout);
Where the partialLayout.xml contains all the GUI components.
Already searched around but it all got a bit confusing to me!
I hope my question is a bit clear, if not (or additional info is needed) I'am happy to edit/provide.
Thanks in advance, regards an android noob
The question is pretty much exactly what I want, lets say i have this text:
"{W}, {T}: Tap target creature."
I have to replace the {W} and the {T} for 2 tiny little images pretty much the same size of the 3 letters(in case {W} and {T})... Is that possible in some way?
Just to say, the TextView is inside a Listview...
the Position for {W} and {T} are not always the same...
the images are in my resource...
The one workaround you can try is to place your TextView and ImageView inside a FrameLayout, one on top of the other. Now when you want to change them, just make one of them invisible and initialize the other. This will probably work. Hope this helps.
Did you try the attribute drawableLeft of the text view? But since you have two images, you will have to use a single image file which consists of both {w}{t}. so you will have to put the images with all combinations of {w}{t} in your resources.
then use the following method in your code:
textView.setCompoundDrawables(leftDrawable, null, null, null);
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.