Non-rectangular TextView - android

I tried searching for a solution, but I couldn't find anything of the sort.
My quest is: is it possible to have a non-rectangular TextView? I need to put a TextView and an ImageView inside a fragment.
Would look something like this:
I was thinking of maybe having two TextViews (lets call them tv1 and tv2) and an ImageView (Img1).
I could align the tv1 to the bottom of img1 and align the top of tv2 with img1. SOMEHOW play with the text in the TextViews to split it in both TextViews?

Flow textview will help to acheive what you want. Here are the few links
http://grishma102.blogspot.in/2013/12/how-to-make-text-flow-around-images-in.html
https://code.google.com/p/android-flowtextview/

Related

How to Prevent TextWrapping programmatically?

How can I prevent a TextView, or any visual object, from wrapping to the screen and instead have them cropped programmatically?
I have a table view which is loaded with TextViews as cells. I need to crop the text inside the textview instead of wrapping.
Is there some code to do this? or is there any workaround?
For example, I have like this:
But what I want is:
I found my own way to fix this. I set the textView.SetMaxLines to 1 and it solved the problem for me.
You can use setSingleLine method:
TextView textView = (TextView) findViewById(...);
textView.setSingleLine(true);
and setEllipsize to remove ellipsize:
textView.setEllipsize(null);

How to combine dynamic an ImageView with TextView

I'd like to fill dynamic ImageViews in a LinearLayout. In addition i like to include at the top of every ImageView a TextView. Implemeting this in a static way with the xml file is no problem but I don't got any idea how to implement this problem?
For example I select 5 pictures out of the gallery and show all pics side by side. At the top of every pic you can see the name of the pic.
[EDIT]
LayoutInflater inflatter=(LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout myLayout = (LinearLayout)findViewById(R.id.mylinlayout);
// AbsoluteLayoute has got an ImageView and a TextView
AbsoluteLayout test = (AbsoluteLayout)inflatter.inflate(R.layout.test2, null, false);
TextView texttest = (TextView)test.findViewById(R.id.name);
ImageView image=(ImageView)test.findViewById(R.id.image);
texttest.setText("test");
myLayout.addView(test);
Sounds like you're trying to make a scrollabe list, where each item in the list is a picture and a title text, right?
Have you thought about using an ArrayAdapter in a ListView and in the adapter's getView() you can inflate a layout file that contains an ImageView and a TextView?
You could create a custom layout in xml with the ImageView and TextView arranged the way you want for each item.
AbsoluteLayout
TextView (above ImageView)
ImageView
Then, as you dynamically get the images, you inflate this custom layout using a LayoutInflater and assign the TextView with the desired text and the ImageView with the desired image. Next, you take the inflated view and add it as a child to the LinearLayout. Iterate through your images and do this and you should have what the desired appearance.
Edit: If you have many images that might require scrolling, you would have to wrap the LinearLayout in a ScrollView to allow scrolling if the LinearLayout gets too large.
As someone else just mentioned, a ListView will take custom xml layouts and inflate them the same way using adapters and such, and it will handle scrolling for you. ListView link and example.

Android : How to adjust Textview

Hello i am trying to display the content i receive in an activity using TextView but it seems that TextView is overlapping a button that i have put in activity's UI.My goal is to put TextView and the button side by side. I have put the TextView in the UI dynamically like this:
String display = extras.getString("EXTRA_MESSAGE");
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setWidth(20);
textView.setHeight(20);
textView.setText(display);
setContentView(textView);
I know i miss something but i cant find what it is,so can you please suggest a way how to fix that?
Thanks a lot in advance!
When you call setContentView(textView); it changes your layout to just the textView so it isn't overlapping your Button but your Button isn't shown anymore. You need to add it to your layout and put it where you want it.
You can do this by getting a reference to your root View in your xml and calling addView(textVie) on that root View and use addRule() to position your TextView where you want. However, if it isn't necessary to add your TextView dynamically then it is much easier to declare it in your xml.
If you do want to add it dynamically still, then this SO answer, and many more, covers it.

How to add two textview with orientation vertical(One below other) in a table row without using xml?

I want add two textview with orientation vertical(One below other) in a table row without using xml that is by programatically. Can anyone suggest me how to do this? Is there any other way than this? Already there are many textviews in a tablerow(horizontally).
Put a LinearLayout in the TableRow cell. Put the two TextView widgets in the LinearLayout. Use Java constructors to create the LinearLayout and the TextView widgets. Use addView() to add the TextView widgets to the LinearLayout.

How to get TextView reference from a custom ImageView?

I would like to ask if there is any methods to get a View from another View.
My case is that:
I have a custom ImageView call MyImageView.
and my layout is that:
FrameLayout:
MyImageView
LiearLayout:
LiearLayout:
TextView
LiearLayout:
TextView
I have some code in MyImageView and I would like to edit the text in TextView under the LinearLayout.
my code in MyImageView for select the TextView is:
TextView textView = (TextView) findViewById(id.TextView01);
However textView is always null and I can't set the text that I prefered.
More, if I code this:
TextView textView = (TextView) findViewById(R.id.TextView01);
Eclipse will give me a error and said can;t resolve the id.
So Is there any methods to edit TextView from a ImageView?
First of all... that's a horrible idea (I would be freaked out if I were you). And it's big signal that you have to rethink how to do your layout.
Anyway, using the getParent method could work:
// in your MyImageView
FrameLayout parent = (FrameLayout)getParent();
TextView textView = (TextView) parent.findViewById(R.id.TextView01);
It's not working the way you are doing it, since the TextViews are not inside your custom view.
I think you can always call getRootView() and from there you can search for a view by Id. As long as the ids are unique within the current view hierarchy you should be able to grab the textView no matter where it is in the hierarchy.
So similar to the other answer
TextView textView = (TextView) getRootView().findViewById(R.id.textview_01);
if it's on the same screen, it will be there always.

Categories

Resources