新手问题,关于ImageView

e9876 2011-03-24 11:55:57

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

ImageView view = new ImageView(this);
LinearLayout layout = new LinearLayout(this);
view.setBackgroundColor(0x00FF0000);
Canvas c = new Canvas();
Paint paint = new Paint();
c.drawText("This Is A Test", 100, 100, paint);
view.draw(c);
view.setMinimumWidth(100);
view.setMinimumHeight(100);

TextView tv = new TextView(this);
tv.setText("This Is Another Test");
layout.addView(view);
layout.addView(tv);
setContentView(layout);
// setContentView(R.layout.main);
}


运行以后,页面只显示了TextView里面的"This Is Another Test"这个字符串
而没有显示"This Is A Test"这个字符串
我的写法是不是错了?如果我希望能在ImageView里面写"This Is A Test"这样的一串字符的话
那我应该怎么写才对?
...全文
239 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
e9876 2011-03-25
  • 打赏
  • 举报
回复
谢谢LS的,解决了。
早应该看看的,呵呵
e9876 2011-03-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 mathcat_ 的回复:]

layout没有setOrientation

给分把~
[/Quote]

应该设成什么才对???
mathcat_ 2011-03-24
  • 打赏
  • 举报
回复
layout没有setOrientation

给分把~
chaoliu1024 2011-03-24
  • 打赏
  • 举报
回复
paint画笔,楼主看看Graphics类
傲力傲 2011-03-24
  • 打赏
  • 举报
回复
不好意思看错了
不过我有一个问题
你那个paint是做什么用的
傲力傲 2011-03-24
  • 打赏
  • 举报
回复
有可能是imageview默认是全屏,线性布局再加一个textview就跑到屏幕外了
e9876 2011-03-24
  • 打赏
  • 举报
回复

ImageView view = new ImageView(this);
LinearLayout layout = new LinearLayout(this);
Canvas c = new Canvas(view.getDrawingCache(true));
Paint paint = new Paint();
c.drawText("This Is A Test!!", 100, 100, paint);
view.draw(c);
view.setMinimumWidth(100);
view.setMinimumHeight(100);

TextView tv = new TextView(this);
tv.setText("This Is Another Test");
TextView tv2 = new TextView(this);
tv2.setText("This Is Third Test");
layout.addView(view);
layout.addView(tv);
layout.addView(tv2);
layout.setOrientation(LinearLayout.VERTICAL);
setContentView(layout);


加入了你们说的那一句,但是依然无效。
e9876 2011-03-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 mathcat_ 的回复:]

引用 2 楼 e9876 的回复:

引用 1 楼 mathcat_ 的回复:

layout没有setOrientation

给分把~


应该设成什么才对???


查DOC啊, 你要横着排就是LinearLayout.HORIZONTAL, 竖着就是VERTICAL
[/Quote]

试过了,无效。。。
AnshuWang 2011-03-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 mathcat_ 的回复:]

引用 2 楼 e9876 的回复:

引用 1 楼 mathcat_ 的回复:

layout没有setOrientation

给分把~


应该设成什么才对???


查DOC啊, 你要横着排就是LinearLayout.HORIZONTAL, 竖着就是VERTICAL
[/Quote]
试一下
mathcat_ 2011-03-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 e9876 的回复:]

引用 1 楼 mathcat_ 的回复:

layout没有setOrientation

给分把~


应该设成什么才对???
[/Quote]

查DOC啊, 你要横着排就是LinearLayout.HORIZONTAL, 竖着就是VERTICAL
tongben11 2011-03-24
  • 打赏
  • 举报
回复
第一个textview 把第二个 textview 覆盖了吧? 重新设定一下坐标。

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧