gpt4 book ai didi

android - 如何在 android 中调整 ListView 的大小?

转载 作者:行者123 更新时间:2023-11-29 15:29:46 25 4
gpt4 key购买 nike

我有一个 android 应用程序,它有一个 ListView ,用于在其中列出 14 个项目。我已经编码为

<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:id="@+id/my_list"/>
</LinearLayout>

我的 Activity 文件正在作为

ListView list;
list = (ListView)findViewById(R.id.my_list);
ArrayAdapter<CharSequence> list_adapter= ArrayAdapter.createFromResource(
this, R.array.my_array, android.R.layout.simple_list_item_1);
my_list.setAdapter(list_adapter);

代码运行正常。但我想减小 ListView 的大小,以便我可以在屏幕上列出最大项目。

我该怎么做?我已经搜索过了。但没有找到任何有用的指导。

最佳答案

明白了亲爱的...

很简单...

我刚刚在 R/layout 中将自己的布局制作为 mylist.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="7pt"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:textColor="@android:color/black"
android:gravity="center"/>

然后我更改了 main.xml 以显示 ListView 。喜欢,

<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/my_list"/>
</LinearLayout>

最后我有了我的 actvty 文件

    // all the stuff
// i cant put my code here,na?:)
//Its simple. just change layout to ours
ListView list;
list = (ListView)findViewById(R.id.my_list);
ArrayAdapter<CharSequence> list_adapter= ArrayAdapter.createFromResource(
this, R.array.my_array, R.layout.mylist);
my_list.setAdapter(list_adapter);

关于android - 如何在 android 中调整 ListView 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8132694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com