简体   繁体   中英

Android Layouts within layouts and making a slideable/scrollable strip within my android app

Im a beginner in android development and a bit stuck, I would like to have a strip in part of my main layout which gets dinamicaly filled and where the user can scroll it sideways to get the info while staying within the main layout. Im currently using a horizontal linearLayout and adding texViews to it, my current code is something like this:

for(Object myObject: objectList){
        LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        TextView tv = new TextView(getContext());
        tv.setLayoutParams(lparams);
        tv.setText(myObject.getData1() + "/n" + myObject.getData2() + "/n" + myObject.getData3());
        myLayout.addView(tv);

    }

Im having 2 problems

  1. I want each myObject to have all its info displayed in a column of the linear layout. Each myObject has 3 (in the future maybe more) pieces of data that I want to display one beneath the other in its column. I thought of making a vertical linearLayout within the horizontal linearLayout and add each piece of data from my object as a textView within the 2nd layout, but nesting layouts like this seemed overly complicated specially since I am making this dinamicaly, I also thought of another layout like a grid layout or something but im not very familiar with all the layouts and since each column should represent an object I felt like spliting the myObjects data into diferent row wasnt correct. Could really use some help in what would be the correct way to do this??

    2- I might have more myObjects in the list that will fit nicely in the screen, how do I make it so that the user can slide it to the left and right to see the other info?? This view is in a fragment and sliding the fragment you go to a diferent fragment, so the user has to be able to scroll this strip without scrolling to a diferent fragment.

Thanks Allot

So I found the answers, thought I would share them in case anyone else had a similar question:

Question 1 - I found this link which helped me get it working: Adding LinearLayout programmatically in Android doesn't work

Question 2, The answer was very simple: I just found out about HorizontalScrollView I put my linear layout inside it and then have text views created dynamically inside it and it is working perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM