动态创建的 TextView 的 setBackgroundResource() 的 xml 文件看起来如何?
我在代码中创建应用程序 GUI(没有布局 xml 文件)。 java代码是:
TextView tv = new TextView (this);
tv.setBackgroundResource (R.drawable.custom_tv);
我不知道应该如何看待这个custom_tv.xml文件。 我尝试这样写:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<ScrollView android:id="@+id/chat_ScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true">
<TextView android:id="@+id/chat_text_chat"
android:text="center chat"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:singleLine="false" />
</ScrollView>
</item>
</layer-list>
但是没有成功。那么,这个xml文件应该怎么看呢?谢谢。
I create application GUI in the code (without layout xml file). The java code is:
TextView tv = new TextView (this);
tv.setBackgroundResource (R.drawable.custom_tv);
I don't know how should look this custom_tv.xml file.
I tried to write it in such a way:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<ScrollView android:id="@+id/chat_ScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true">
<TextView android:id="@+id/chat_text_chat"
android:text="center chat"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:singleLine="false" />
</ScrollView>
</item>
</layer-list>
But it didn't work. So, how should look this xml file? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太确定为什么你要使用 ScrollView 来执行此操作,假设你每次都添加多个文本视图?如果需要的话,用一个文本视图替换滚动视图并更改文本不是更好吗?
I'm not very sure why you are doing this using a ScrollView assuming that you add multiple textviews everytime? Wouldn't it be better to replace the scrollview with one textview and change the text if you need to?