Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8460303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:34:11+00:00 2026-06-10T13:34:11+00:00

Is it possible to create an dynamic layout in a AppWidgetProvider ? i only

  • 0

Is it possible to create an dynamic layout in a AppWidgetProvider ? i only found tutorials to create widgets using XML, but it isn’t possible to create views that way..

I want to draw images in row like this: https://i.stack.imgur.com/rgtil.jpg
And add a horizontal scroll. Is it possible ?

Regards !

EDIT: (this is what i have so far.. but i still don’t know how to add those images)

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {
    // TODO Auto-generated method stub
    super.onUpdate(context, appWidgetManager, appWidgetIds);
    final int N = appWidgetIds.length;
    for(int i = 0; i<N; i++){
        int awID = appWidgetIds[i];
        RemoteViews v = new RemoteViews(context.getPackageName(), R.layout.about);
        try
        {
            j = 1;
            Set<User> users = LFMRestConnection.getFriendsNowListening(user, 1440);;
            for (User u : users) {
                album_pic = loadBitmap(u.getImageURL().getImageURL(ImageURL.Size.LARGE));
                resized_a_p = android.graphics.Bitmap.createScaledBitmap(album_pic, (50), (50), true);
            //URLS
                url_to_enter[j]=u.getLastTrack().getArtistName();
                track_to_enter[j]=u.getLastTrack().getTrackName();
            //profile picture
                user_pic = loadBitmap(u.getImageURL().getImageURL(ImageURL.Size.LARGE));
                resized_u_p = android.graphics.Bitmap.createScaledBitmap(user_pic, (25), (25), true);
                j++; 
            }
        }
        catch(Exception e)
        {
            //startActivity(i);
            System.out.println("widget error");     
        }
        appWidgetManager.updateAppWidget(awID, v);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:34:12+00:00Added an answer on June 10, 2026 at 1:34 pm

    Create a HorizontalScrollView in your xml layout, put a horizontal LinearLayout in it, and give the layout an ID by setting the id attribute

    android:id="@+id/imageScrollLayout"
    

    Then, in the onCreate for your activity, find the layout object

    LinearLayout imageScrollLayout = (LinearLayout)findViewById(R.id.imageScrollLayout); 
    

    To add new ImageViews to the layout dynamically, use

    ImageView newImageView=new ImageView();
    
    //set the ImageView image with one of the following:
    newImageView.setImageBitmap(bm);
    newImageView.setImageDrawable(drawable);
    newImageView.setImageResource(resId);
    
    //add the new ImageView to your layout
    imageScrollLayout.addView(newImageView);
    

    All the xml settings for the ImageView can be accessed in code, just set them after you set your image. The Google Android documentation is pretty good for finding all the relevant methods. Also, if you’re adding images anywhere but the onCreate method for your activity, just remember to make imageScrollLayout a field in the activity, rather local in the onCreate method, so you can access it everywhere.

    EDIT: To implement this in an AppWidgetProvider, you need to override the onUpdate method. This method is called whenever the system is requesting an update for the widget. If the RemoteViews of the widget do need to be changed, you need to create a new set of views, and attach them to the widget using

    appWidgetManager.updateAppWidget(componentName, remoteViews)
    

    where appWidgetManager is a supplied argument to the onUpdate method. A similar process needs to be implemented in the onAppWidgetOptionsChanged() method. To supply the remoteViews argument, inflate the layout file in code using something to the effect of

    LayoutInflater myInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
    final View myRootLayout = myInflater .inflate(R.layout.myLayout, null);
    

    after which you can use the normal

    myRootLayout.findViewById(R.id.myView);
    

    to find your layout and add ImageViews to it.

    After all that, I suspect that HorizontalScrollView is not supported as a RemoteView, making it hard to implement the horizontal scrolling you want. This has likely been a design decision by Google, as horizontal scrolling in an AppWidget would not work well with the horizontal scrolling between homescreens. Maybe use left and right edge buttons instead, to show a new page of images?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to create a dynamic array using something like this and store
Is it possible to create a dynamic xml file which changes in some fields
Wondering if it's possible to create a dynamic linq query using linq to objects.
Is it possible to create a dynamic SQL statement that pulls from an existing
i am asking myself if it is possible to somehow create a dynamic gui
Possible Duplicate: Create an Array of the Last 30 Days Using PHP I am
Is it possible to create a dynamic context menu in android? What I mean
Is it possible to create dynamic js file creation? e.g. I am referring MyJs.js
Is it possible to create an object from a class with a dynamic name?
Is it possible to create dynamic HTML page with Javascript ? Now or tomorrow...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.