Drawing texts on a static layout like textview, and the texts are an item on a recyclerview. Normally, the textview has getSelectionStart() and getSelectionEnd() functions but how to get the selection positions using a static layout?
StaticLayout should not be used in most of the cases. As stated in Android Developer Guides: "You should not need to use this class directly unless you are implementing your own widget or custom display object, or would be tempted to call Canvas.drawText() directly."
It is a very low-level component for drawing text. It is mostly used in specific situations e.g. when you want to draw text on bitmaps, or measure the size of the TextView before it is created, etc.
Therefore, it doesn't contain any API for handling text selection. That is implemented in TextView (which also uses StaticLayout under the hood).
Using just TextViews can in no situation affect performance of the app. Even with huge amounts of data, if you properly recycle TextViews in your RecyclerView using the mandatory ViewHolder, you will never have more TextViews than visible on the screen, only the text content will change as they get recycled/re-inserted, so there's no performance gain in avoiding them.
Related
So I have a question about best practice for dynamically creating and sizing buttons within a ViewPager, based on a changing external state.
Essentially, I have a scrolling view and I want my ViewPager to contain a number of buttons of a specific size and count depending on what part of the scrolling view is currently visible.
My question is about deciding the best implementation of this feature, I see two options: would it be simpler to
Constantly create and scale new buttons whenever the scrolling view moves
Make the viewpager itself contain a scrollview and fill it with all of the pre-scaled buttons on app startup. Then, whenever the user scrolls the main scrollview the viewpager's scrollview (which contains the buttons) will scale programatically
Any ideas on which would be the simpler and more robust system?
Not much of an answer but I will leave a comment for ya! Basically you can do it either way, both aren't to difficult to accomplish, however I would probably go the dynamic route because it will always scale correctly. Doing a set amount will only work until devices become larger, or if you are targeting tablets or tvs then it will start to become extremely messy in the xml file for the layout. Dynamically adding also gives you far more control and saves time later on, you can simply change a number and have 100 more then going through and manually adding even 10. Hope this helps!
In my app, I have a screen that displays some images next to text. These images are downloaded from the internet, so there will be some latency in displaying them. Right now I have an ImageView and a ProgressBar overlaying each other, and toggling the visibilities when the Bitmap becomes available. Is there any way to combine the two into one class that will handle it all in case I want to use this somewhere else?
One way to go about solving the problem is to make your own custom view which extends ProgressBar and draw the image in the ondraw(Canvasn canvas) using a Rect. That way, your image can be embedded in your view and you can always make it reusable by allowing your self to set the image via a setter/resource xml files which specify the attributes that go along with your custom view. Here's a reusable ProgressButton that I wrote that maybe of use to you, it shows how I did something similar to what I described (it's one which I think works well):
PregressButton
Yes there are a number of ways to combine widgets into a single custom class. Have a read of Custom Components. This should help you decide which approach you want to use for your situation.
i'm making an app that requires indefinite textviews and images. i'm trying to implement a Pulse News app UI but having a hard time implementing one. so i thought of an idea to make a UI like that with the use of textviews, imageview and horizontal scroll view.
textview string values are from parsed xml online and images or the imageviews will be images from a specific directory in the sdcard that my app is using.
can anyone give me ideas how can i do it without using an xml layout or is there any or other options or ways for doing this? thanks...
You can create a viewgroup with one textview and an image. Then it can be added dynamically to your layout many times. This can be done by creating objects in a loop. You can change the content in each viewgroup at the time of inflation.
though i dont know what exactly how pulse new app looks like, but by going through your question (horizontal scroll view in particular) I guess you want to implement a "Gallery" type implementation where in you can swipe left/right on page basis.
If my assumption is correct then you will like to see to ViewPager of android backward compatiblity pkg.
When using developing Widgets for Android it seems you are not able to add your own custom View classes to a AppWidgetProvider.
For example I created a custom class which extends View, this works fine when used within an Activity but the moment I add it to a Widget I get a "ClassNotFoundException" because Android seems to only allow a set of certain system widgets to be added.
I have seen some apps which look like they have made there own custom widgets. For example there is one that brings up a radial menu when clicked which shows application shortcuts. How are these being implemented? Is there a work around to using my own custom widget? They seem to have a canvas which they are able to draw on within the widget.
Okay quick example https://market.android.com/details?id=zombiesinthelab.widgets.droidpetwidget&feature=top-paid
So this widget is being done by just drawing ImageViews and updating them periodically opposed to using a canvas to draw the frames?
Android Widgets can only contain Layout-Widgets supported by RemoteViews. See this list:
A RemoteViews object (and,
consequently, an App Widget) can
support the following layout classes:
FrameLayout
LinearLayout
RelativeLayout
And the following widget classes:
AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
> Descendants of these classes are not
supported.
Pay attention to the last sentence. You can not change this behaviour, it is hard coded in android.
I have not much idea on how to create widgets but following links can definitely help you:
1) http://developer.android.com/guide/topics/appwidgets/index.html
2) http://developer.android.com/guide/practices/ui_guidelines/widget_design.html
Is it possible to use the VideoVideo with the ListView as an item. Has anyone done this? Are there any issues I should be aware of?
I've made a test.Videoview can be inserted into a listview, it can work properly.But when i drag the list, the area which the videoview once occupied will get in front of the screen. Andt the screen will get very dirty.
Is it possible to use the VideoVideo with the ListView as an item.
I doubt it. SurfaceView -- which VideoView uses -- does not behave much like a normal widget. IIRC, you cannot have two SurfaceView widgets active at the same time, regardless of what contains them.