【发布时间】:2015-11-16 20:22:54
【问题描述】:
我需要这样的东西:
线性布局(修复)
- 按钮
线性布局
- 滚动视图
- 文本视图
- 文本视图
- 文本视图
我希望修复第一个 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);
【问题讨论】:
-
您可以将其创建为布局 xml,然后对其进行膨胀。那会更容易处理。
LayoutInflater inflater = LayoutInflater.from(getContext()); View view = inflater.inflate(R.layout.yourLayout, yourContainer, attachToRootOrNot); -
我该怎么做呢?你能说得更具体点吗?
-
只需通过布局编辑器或手动编写 xml 为您的视图创建一个布局,然后像我写的那样调用它。比通过例如
Button button = view.findViewById(R.id.btn);调用儿童视图编辑:您可以在 betone.co.uk 上查看我的应用程序视频。如果其中一个屏幕就像您想要实现的那样,我可以将那部分代码分享给您
标签: java android android-layout android-linearlayout android-scroll