Skip to content Skip to sidebar Skip to footer

How To Have Dynamically A Fixed Header With Scrollable Content In Android?

I have created programmatically a RelativeLayout which contains a button. I have also created a ScrollView which contains a LinearLayout in which are more than 10 TextViews. I want

Solution 1:

In your code you replace your RelativeLayout with ScrollView. Just set firstly some LinearLayout as contentView and then put there your RelativeLayout via addView(relativeLayout) and the put there you scrollView also via addView(scrollView)

EDIT:

your new code:

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        finalLinearLayoutmainLinearLayout=newLinearLayout(this);
        LinearLayout.LayoutParamsmainLinearLayoutParams=newLinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        mainLinearLayout.setLayoutParams(mainLinearLayoutParams);
        mainLinearLayout.setOrientation(LinearLayout.VERTICAL);
        this.setContentView(mainLinearLayout);

        finalRelativeLayoutrelativeLayout=newRelativeLayout(this);
        RelativeLayout.LayoutParamsrelativeLayoutParams=newRelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        relativeLayout.setLayoutParams(relativeLayoutParams);
        mainLinearLayout.addView(relativeLayout);

        finalButtonrestartButton=newButton(this);
        restartButton.setText(R.string.restartButton);
        LinearLayout.LayoutParamsbuttonParams=newLinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        restartButton.setLayoutParams(buttonParams);
        relativeLayout.addView(restartButton);

        ScrollViewscrollView=newScrollView(this);
        mainLinearLayout.addView(scrollView);

        finalLinearLayoutlinearLayout=newLinearLayout(this);
        LinearLayout.LayoutParamslinearLayoutParams=newLinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        linearLayout.setLayoutParams(linearLayoutParams);
        linearLayout.setOrientation(linearLayout.VERTICAL);
        scrollView.addView(linearLayout);

        TextViewtextView1=newTextView(this);
        testTitle.setText(R.string.text_view1);
        linearLayout.addView(textView1);

        // + other 10 text views
    }

EDIT 2: renamed first linearLayout to mainLinearLayout according to the comment

Post a Comment for "How To Have Dynamically A Fixed Header With Scrollable Content In Android?"