如何在Android中以编程方式添加修复线性布局?

时间:2015-11-16 20:22:54

标签: java android android-layout android-linearlayout android-scroll

我需要这样的事情:

LinearLayout(修复)
  - 按钮
的LinearLayout
  - ScrollView
  - TextView
  - TextView
  - TextView

我希望修复第一个LinearLayout(如标题)。当有人试图向下滚动时,我希望TextView在修复LinearLayout后面。我希望该按钮始终可见。使用此代码,所有内容都向下滚动。 这是我的代码:

    ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView);

    final LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(linearLayout.VERTICAL);
    scrollView.addView(linearLayout);

    final LinearLayout topLinearLayout = new LinearLayout(this);
    topLinearLayout.setOrientation(topLinearLayout.VERTICAL);
    linearLayout.addView(topLinearLayout);

    final Button button = new Button(this);
    button.setText(R.string.button);
    topLinearLayout.addView(button);

    TextView title = new TextView(this);
    title.setText(R.string.title);
    title.setGravity(Gravity.CENTER);
    linearLayout.addView(title);

1 个答案:

答案 0 :(得分:0)

您要将$(document).ready(function(){ $('.whyus').animate({right: "+=500px",}, 5000 ); }); 添加到topLinearLayout中,并在linearLayout中添加scrollView。这不是你想要的。

在另一个scrollView

中添加topLinearLayoutLinearLayout
final LinearLayout mainlinearLayout = new LinearLayout(this);
mainlinearLayout.setOrientation(linearLayout.VERTICAL);

ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView);

final LinearLayout topLinearLayout = new LinearLayout(this);
topLinearLayout.setOrientation(topLinearLayout.VERTICAL);

mainlinearLayout.addView(topLinearLayout); 
mainlinearLayout.addView(scrollView);

final LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(linearLayout.VERTICAL);
scrollView.addView(linearLayout);

final Button button = new Button(this);
button.setText(R.string.button);
topLinearLayout.addView(button);

TextView title = new TextView(this);
title.setText(R.string.title);
title.setGravity(Gravity.CENTER);
linearLayout.addView(title);