更改扩展 ListActivity 的 Activity 的背景图像

发布于 2024-12-10 16:11:28 字数 999 浏览 8 评论 0原文

我遵循以下教程: http://mobile.tutsplus.com/tutorials/android/ android-listview/ 并能够成功运行该应用程序。它主要使用一个名为 list_item.xml 的 xml 文件,其内容为

<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="24dp"
android:padding="6dp" />

在名为 TutListActivity.java 的文件中,此 xml 加载为:

public class TutListActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setListAdapter(ArrayAdapter.createFromResource(getApplicationContext(),
            R.array.tut_titles, R.layout.list_item));
}}

这是应用程序首次启动时加载的第一个活动。我的要求是更改整个屏幕的背景视图。当我在 xml 文件 list_item.xml 中尝试 android:background=@drawable/paperImage 时,我能够更改列表中每行的背景图像,而不是完整视图。有人能帮我吗?

I followed the tutorial at: http://mobile.tutsplus.com/tutorials/android/android-listview/
and was able to successfully run the application. It mainly uses a xml file called list_item.xml and its contents are

<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="24dp"
android:padding="6dp" />

And in a file called TutListActivity.java, this xml is loaded as:

public class TutListActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setListAdapter(ArrayAdapter.createFromResource(getApplicationContext(),
            R.array.tut_titles, R.layout.list_item));
}}

AND THIS IS THE FIRST ACTIVITY WHICH GETS LOADED WHEN THE APPLICATION IS LAUNCHED FIRST. My requirement is TO CHANGE THE BACKGROUND VIEW OF THE COMPLETE SCREEN. When I tried android:background=@drawable/paperImage in the xml file list_item.xml, I was able to change the background image of each of the rows in the List and not the complete View. Can anyone help me out ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

夜清冷一曲。 2024-12-17 16:11:28

只需在 setListAdapter 之后使用下面写的以下行和图像的 id 我希望这就是您想要的

ListView lv = getListView();
    lv.setCacheColorHint(0);
    lv.setBackgroundResource(R.drawable.myMainBackground);

just use the following lines written below with the id of your image after setListAdapter i hope this is what you want

ListView lv = getListView();
    lv.setCacheColorHint(0);
    lv.setBackgroundResource(R.drawable.myMainBackground);
ㄟ。诗瑗 2024-12-17 16:11:28

您为列表视图指定了 2 个 xml 布局。 1 用于活动,另一个用于列表视图的一行。您应该设置用于活动的布局的背景,即您在 setContentView 中放置的布局。现在您正在将背景图像设置为行 xml 文件。

There are 2 xml layouts you specify for the listview. 1 is for the activity and the other is for a row of the listview. You should set the background for layout used for the activity ie the layout you put in setContentView. Right now you are setting the background image to the row xml file.

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