How to dynamically load imagebuttons on android? - java

as the title says, I am trying to figure out how to dynamically load imagebuttons using Android Studio. I have already pre-loaded the drawable folder with all of the images I want to make into imagebuttons.
I am using a relativelayout for this app and the main screen will scroll down. I am trying to do this without using the XML file since it seems like it makes it harder to do things dynamically.
How can I create x number of imagebuttons with these conditions? If using the xml folder would make it easier, can someone help me understand it better?

Create a custom ScrollView which find that user reach to bottom. Then inflate your view which have ImageButton. Add that inflated view in your RelativeLayout or LinearLayout which will be inside ScrollView.
Refer this:- Detect end of ScrollView

Related

How to expand a cardView to show hidden elements in android with a dropping animation?

I am beginner in android animations and therefore, am wondering exactly how can I implement something like expand a cardView to show hidden options or elements.
For example: a post in social networking, we have a cardView holding the post info. it also has likes and comments buttons/options. When user taps on comments button the view should expand a little say certain height and show the comments and shrink back when the same button is tapped again.
I am listing my posts using RecyclerView in a Fragment using a CardView. I am looking for a soft animation along with expanding and shrinking back to original place or size.
Below is a screenshot that might help you understand what exactly I want:
How to do this? Will you please provide me a small snippet of code?
use wrap content as height of cardview and use textview inside it below title, so on click make the textview visible and invisible.
And use android:animateLayoutChanges="true" in parent layout.

loading bar inside listView

I'm creating an app, that loads 2 xmls in listView (second one is loading when first scrolled down to the bottom).
So I want to show loading bar when 2nd xml is loading and parsing inside listView like on the second pic;
Is this even possible? :)
Because I have to put it on the layout and move my listView (thats not looking good).
Thanks
For first time loading you want progress bar to be loaded in screen center. so you make in your layout two element. one listview that covers whole screen and after that put progressview ... put them in master layout as Relative, so they will automatically adjust like listeview will be behind and progressview will be on top of it. in activity code set progressview visible on your server request. after first load when items are all loaded in adapter, hide progressview ...
for on scroll and infinite scrolling/loading here is a decent library that does that easily https://github.com/pwittchen/InfiniteScroll

How to create this Setting Layout in android?

I want to create a settting UI like this in android:
Questions:
How to create the layout? I believe it's a Vertical LinearLayout containing some of TextView with Divider set, is that right?
How to create sub-textview? (see the image above)
How to create a checkbox which aligned at right? (again, see the image above)
Look at the image above, the "Keypress popup" can be clicked and it will show up a dialog. How to create a clickable TextView? I have tried giving android:onClick on the TextView, but nothing happened when I clicked the TextView.
PreferenceActivity will help you to implement all these very easily. Go through this and this tutorials.
PreferenceFragment should be used post Honeycomb.

Create multiple horizontal scrolling layouts within a scroll view

So I have a Scroll View which contains a relative layout. I want that relative layout to have 3 or more layouts that can be scrolled. I know how to implement that with HorizontalScrollView, but before execution, I have no idea how many elements the HorizontalScrollView is going to have. Should I use ViewPager for this? What I would like the most is a HorizontalListView.
Would you recommend something like this:
https://github.com/sephiroth74/HorizontalVariableListView
Or should I add views programmatically in a HorizontalScrollView?
ScrollView is widget that should be used to keep static layouts inside. In general - ones that just are ~slightly bigger that the screen.
If you need something really dynamic you should use elements based on adapters like ListView, or ViewPager.

Multiple TextViews in a SurfaceView

I am creating an android game, I tried using the canvas.drawText() method to display my score and level but it caused errors. Now I am trying to use TextViews to display them, I am using a SurfaceVeiw and I wanted to know is it possible and would it be a good way of doing it.
You can't really put TextViews into a SurfaceView. What you can do instead, though, is add TextViews on top of the SurfaceView. Let me know if you need help on doing that if you don't know how.
// You can use a FrameLayout to hold the surface view
FrameLayout frameLayout = new FrameLayout(this);
frameLayout.addView(surfaceView);
// Then create a layout to hold everything, for example a RelativeLayout
RelativeLayout relativeLayout= new RelativeLayout(this);
relativeLayout.addView(frameLayout);
relativeLayout.addView(textview1);
relativeLayout.addView(textview2);
setContentView(relativeLayout);
When adding your views, it may be helpful to using LayoutParams to help organize things. Use this documentation for LayoutParams. Hope this helps!
If you're using an XML layout, I would use a RelativeLayout, as mentioned above, contain the SurfaceView inside a FrameLayout. Placing the TextView's on top of the FrameLayout is just a simple matter of configuring the RelativeLayout parameters for each view. You seem new to Android, perhaps this guide will help you with RelativeLayouts and XML layouts in general.

Categories