动态创建的 TextView 的 setBackgroundResource() 的 xml 文件看起来如何?

发布于 2024-12-25 19:56:22 字数 968 浏览 1 评论 0原文

我在代码中创建应用程序 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

要走就滚别墨迹 2025-01-01 19:56:22

我不太确定为什么你要使用 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文