GithubHelp home page GithubHelp logo

Comments (2)

krishnalalstha avatar krishnalalstha commented on August 19, 2024

The code is Same what it has in horizontalList. Problem here is Horizontal
list has no effect on wrap_content as it takes match parent

On Tue, May 13, 2014 at 11:10 PM, Troy Locke [email protected]:

Could you send some sample code. Or post your layout here.


Reply to this email directly or view it on GitHubhttps://github.com//issues/43#issuecomment-42985540
.

from devsmartlib-android.

azzits avatar azzits commented on August 19, 2024

Managed to make it work, now the content width is set to wrap_content and you can give gravity to your parent layout.

Add this function to the component class file.
public void resetPosition() {

if (mContext != null && mAdapter != null) {

    DisplayMetrics metrics = mContext.getResources()
            .getDisplayMetrics();
    int width = metrics.widthPixels;

    if (mAdapter.getCount() * mChildWidth > 0
            && mAdapter.getCount() * mChildWidth < width) {

        Log.e("child width", "child: " + mAdapter.getCount()
                + ": width:" + mChildWidth + "");

        setLayoutParams(new LinearLayout.LayoutParams(
                mAdapter.getCount() * mChildWidth, 300));
    }
}

}
After you set the adapter/notifydatasetchanged

call the function like

yourHorizontalListView.post(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            yourHorizontalListView.resetPosition();

        }
    }); 

Worked in my case.

from devsmartlib-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.