Android 如何动态清除和设置ScrollView的内容?
我是Android开发新手,在我的Android 如何动态清除和设置ScrollView的内容?,android,android-layout,Android,Android Layout,我是Android开发新手,在我的ScrollView中挣扎了很多,实际上我想做以下几点: 将其内容设置为我的一个版面,例如:scrollView.setContent(R.layout.activity\u payment) 清除其内容,例如:scrollView.clearContent() 有人能告诉我如何实现上述语句的代码吗?其实很简单: 覆盖滚动视图: public class ClearScrollView extends ScrollView 添加两种方法: public v
ScrollView
中挣扎了很多,实际上我想做以下几点:
- 将其内容设置为我的一个版面,例如:
scrollView.setContent(R.layout.activity\u payment)
- 清除其内容,例如:
scrollView.clearContent()
有人能告诉我如何实现上述语句的代码吗?其实很简单: 覆盖
滚动视图
:
public class ClearScrollView extends ScrollView
添加两种方法:
public void setContent(@LayoutRes int layoutRes) {
View view = LayoutInflater.from(getContext()).inflate(layoutRes, this, false);
this.addView(view);
}
public void clearContent() {
this.removeAllViews();
}
仅此而已。在任何需要的地方使用滚动视图