如何在列表视图中显示固定行数

2024-02-25

我只想显示 5 行ListView其余的应该是scrollable.到目前为止我已经尝试过这个

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <EditText 
        android:id="@+id/txtFilename"
        android:layout_width="375dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp" />

    <ListView
        android:id="@+id/ListView01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbarSize="2dp"
        android:

        /> 



     <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/gray"
        android:padding="5dp" >

        <Button 
            android:id="@+id/btnOk"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="OK"/>

        <Button 
            android:id="@+id/btnCancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="CANCEL"/>
    </LinearLayout>  


</LinearLayout>

and in java code

public class MainActivity extends Activity {

    private ListView list1;

    private String array[] = { "Iphone", "Tutorials", "Gallery", "Android",

    "item 1", "item 2", "item3", "item 4" };
    @SuppressWarnings("unchecked")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        //parentLayout.add(childLayout);

        setContentView(R.layout.activity_main);
        list1 = (ListView) findViewById(R.id.ListView01);

        // By using setAdpater method in listview we an add string array in

        // list.

        list1.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1, array));

    }

知道如何实现它


我在这里只是修改你的Layout看看吧!

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <EditText 
        android:id="@+id/txtFilename"
        android:layout_width="375dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp" />
<LinearLayout
         android:layout_width="fill_parent"
         android:layout_height="300dip">
    <ListView
        android:id="@+id/ListView01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbarSize="2dp"


        /> 


</LinearLayout>
     <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/gray"
        android:padding="5dp" >

        <Button 
            android:id="@+id/btnOk"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="OK"/>

        <Button 
            android:id="@+id/btnCancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="CANCEL"/>
    </LinearLayout>  


</LinearLayout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在列表视图中显示固定行数 的相关文章

  • 将数据从服务传递到活动

    我有自行运行的服务 服务自动启动 我有活动 在此 Activity 按钮中启动该方法DoIt Button setOnClickListener new OnClickListener public void onClick View v
  • Android主线程的IO操作

    我的问题有两个 是否建议在 Android 的主线程上进行 IO 操作 或者它是否有可能导致我的应用程序崩溃 如果在主线程上执行 IO 操作不理想 我可以使用哪些其他框架 以便当我的应用程序加载时它可以执行一些基本的 IO 文件读取并将值存
  • 如何替换 Android 中已弃用的 Bundle/Argument get(key) 调用

    我有以下扩展函数 允许我在应用程序活动和片段之间传递捆绑数据项 inline fun
  • 如何使用 gradle 从 3 个子模块构建 1 个 jar

    I have 安卓工作室3 gradle 4 1 梯度工具3 classpath com android tools build gradle 3 0 1 当我有一个模块并使用 gradle 工具 2 时 我使用了 task makeJar
  • 如何在android中显示对话框之外的图像?

    我试图在对话框片段的顶部显示配置文件图像 一半在图像之外 我在下面附加了示例对话框 就像那样 并尝试了旧 Stackoverflow 解决方案中的所有 FrameLayout 协作 但我无法存档此内容 请给我正确的解决方案 谢谢 Updat
  • 使用 Fragment 在工具栏中实现 SearchView

    当前情况 我的应用程序主页由导航抽屉组成 因此我将视图作为片段加载 我的工具栏中也有搜索图标 我在中实现了它menu xml 下一步我实施了SearchView通过以下问题的答案来获取搜索图标在工具栏中实现搜索 https stackove
  • socket.io xhr 在连接缓慢时出现错误(3G 移动网络)

    当我在 3G 移动网络 互联网连接速度慢 上测试我的真实聊天应用程序时 Socket io反复断开然后重新连接 我已经记录了原因 它说 xhr post error 这提高了 transport error 然后断开连接 我可以知道什么意思
  • 带有 Android 支持库 v7 的 Maven Android 插件

    我使用 maven android plugin 构建我的 android 应用程序 它依赖于 android 支持库 v4 和 v7 由于我没有找到如何从developer android com下载整个sdk 因此我无法使用maven
  • 改造中的多个队列导致内存不足错误?

    我正在使用retrofit2 做我的项目 当我的呼叫失败时 我再次重复相同的呼叫 重复此 呼叫使我的应用程序强制关闭 当我查看日志时 我得到了错误日志 如下所示 我觉得这是由于同一呼叫的多次排队造成的 所以我在排队之前就这样做了 我打电话给
  • Fragment 问题中的 ExpandableListView

    我正在尝试在片段中实现可扩展列表视图 没有错误出现 当我尝试记录两个的输出时List
  • Ionic 2 RC0 和 Angular 2 最新的 Android 构建错误(ngc:错误:静态解析符号值时遇到错误)

    当我使用构建android时出现错误ionic build android命令 ngc 错误 静态解析符号值时遇到错误 引用本地 非导出 符号 字典 考虑导出符号 原始 ts文件中的位置14 8 解析符号TRANSLATION PROVID
  • Android上如何获取ImageView的Drawable的矩形?

    我想要获取将包裹 ImageView 的 Drawable 的矩形对象 而不是包裹 ImageView 的矩形 我将使用该矩形在 Drawable 周围绘制一些奇特的矩形 我怎样才能得到那个矩形 Rect rect new Rect Ima
  • React Native Expo StackNavigator 重叠通知栏

    我正在尝试为我的 React Native Expo 应用程序实现导航栏 这里有一个问题 dependencies expo 18 0 3 react 16 0 0 alpha 12 react native 0 45 1 react na
  • MIUI 权限被拒绝活动 KeyguardLocked

    当应用程序处于后台且屏幕被锁定时 我无法启动活动 没有异常或警告 只是不调用 onCreate 我一直在与这个问题作斗争 我想我终于找到了它的根源 日志中有一行 D com android server am ExtraActivityMa
  • 如何将 Android 添加到 Phonegap 平台版本 3

    经过大量挖掘 我相信这个问题 https stackoverflow com questions 18423444 phonegap 3 doesnt work with andriod studio与我没有添加任何用于构建phonegap
  • Android 中的 OpenGL 缩小

    我正在使用 3D 对象并渲染它并通过扩展 GLSurfaceView 实现渲染器来显示它 问题是如何通过捏合和捏合进行缩小 下面是我的班级 package com example objLoader import java nio Byte
  • 使用 Play Integrity API 时,Firebase 电话身份验证会出现缺少客户端标识符错误

    使用 Firebase 电话身份验证注册 登录时 身份验证流程始终会启动 reCAPTCHA 流程 并在返回应用程序后发出missing client identifier error 我的设置之前适用于设备验证 安全网络 API 除了我的
  • Android 中的库可以有自己的意图过滤器吗?

    我想开发一个可以包含在其他 Android 应用程序中的库来拦截某些类型的意图 是否可以 我创建了一个库和一个测试项目 两者都有自己的AndroidManifest xml文件 在库的清单中 我为操作 TEST 定义了一个意图过滤器 但是
  • Android SearchView 在启动时隐藏键盘

    我有一个小问题正在尝试解决 当我打开应用程序时 键盘会显示输入搜索视图的查询 不过 我只想在单击搜索视图时显示键盘 我该如何解决 Thanks 这对我有用 用于隐藏焦点的代码 searchView SearchView view findV
  • 如何访问我的 Android 程序中的联系人

    我正在制作一个短信应用程序 并且想要访问我的 Android 应用程序中的联系人 我想访问联系人 就像他们在实际联系人列表中一样 选择后 我需要返回到我的活动 在其中我可以向该人发送短信 或者是否可以访问存储联系人的数据库 我的代码如下所示

随机推荐