How to create Scrollview programmatically?

后端 未结 5 578
一向
一向 2021-02-07 20:01

I have one table \"TABLE_SUBJECT\" which contain a number of subjects. I need to create
one horizontal scroll view with Subject.

How do I create a ScrollView with da

5条回答
  •  有刺的猬
    2021-02-07 20:58

    if you have many elements first you need to wrap-up and add in the Scroll view; for example i need a many text view inside of scrollview, so you need to create ScrollView->LinearLayout->Many textview

                    ScrollView scrollView = new ScrollView(context);
                    scrollView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    
                    TextView textView = new TextView(context);
                    textView.setText("my text");
    
                    LinearLayout linearLayout = new LinearLayout(context);
                    linearLayout.setOrientation(LinearLayout.VERTICAL);
                    linearLayout.setGravity(Gravity.RIGHT);
                    linearLayout.addView(textView);
                    scrollView.addView(linearLayout);
    

提交回复
热议问题