java滚动视图编程
我需要直接从Java代码创建一个scrollview,所以我编写了这段代码(我在AlertDialog中使用)
TextView myTextView = new TextView(context);
myTextView.setText("Very long text" + longTextVariable);
ScrollView scroll = new ScrollView(context);
scroll.setBackgroundColor(安卓.R.color.transparent);
scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
builder.setView(myTextView);
builder.setView(scroll);
但它不起作用,因为我什么也看不见。为了让你明白我在做什么,我只告诉你,我需要显示的文本非常长,没有滚动视图是“剪切”
# 1 楼答案
试试这个:
# 2 楼答案
首先将
myTextView
设置为builder
中的视图,然后将其替换为scroll
。这样,您只有一个空的滚动视图您需要将
myTextView
添加到scrollview
,然后将scrollview
添加到builder
# 3 楼答案
首先需要在ScrollView中添加TextView,然后添加此ScrollView警报
谢谢