How can I do something like a FlowLayout in Android?

后端 未结 9 1394
情歌与酒
情歌与酒 2020-11-22 08:11

How can I do something like a FlowLayout in Android?

9条回答
  •  孤独总比滥情好
    2020-11-22 08:42

    Nice simple self-contained FlowLayout code here (just a few concise gist.github files):

    http://hzqtc.github.io/2013/12/android-custom-layout-flowlayout.html

    However, the activity there out of the box didn't work for me to load the custom layout.

    I found this work-around [ using the 2-param .inflate() call from this example ]:

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // ..
    
        setContentView(R.layout.main_res_layout_activity_main);
    
        ViewGroup flowContainer = getFlowLayoutView(); 
    
        // ..
    }
    
    ViewGroup getFlowLayoutView()
    {
        LayoutInflater inflater = getLayoutInflater();
    
        ViewGroup flowLayout = 
            (ViewGroup)
                inflater.inflate(
                        R.layout.main_res_layout_activity_main,
                        (FlowLayout) findViewById(R.id.flow_container)
                );
    
        return flowLayout;
    }
    

提交回复
热议问题