滚动菜单ListView

activity_main.xml

<include layout="@layout/title"/>

引用上章自定义标题栏

复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <include layout="@layout/title"/>

    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

MainActivity.java

复制代码
    private String[] data = {"Apple","Banana","Apple","Banana","Apple","Banana","Apple","Banana","Apple","Banana"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //隐藏系统自带标题栏
        ActionBar actionBar = getSupportActionBar();
        if(actionBar!=null){
            actionBar.hide();
        }

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1,data);
        ListView listView = findViewById(R.id.list_view);
        listView.setAdapter(adapter);
    }

当String\[\]中的数据足够的,超出屏幕即可滑动查看

相关推荐
开发者导航8 分钟前
Cursor plugins 插件仓库上手:结构解析与安装使用教程
android·linux·ubuntu·ai·typescript·cursor·插件开发
大数据女孩_Aimee3 小时前
安卓15CTS:CtsCompilationTestCases模块测试FAIL
android·模块测试
箓维17 小时前
MySQL_表的约束
android·数据库·mysql
HEJOO920 小时前
MySQL 日期时间类型怎么选:DATE、DATETIME、TIMESTAMP、TIME、YEAR 全解析
android·数据库·mysql
风早爽太21 小时前
Android 开发笔记:封装 Fragment 的管理工具类
android·kotlin
峥嵘life21 小时前
Android 17 具体代码新特性总结
android·开发语言·网络
王者鳜錸1 天前
Android 接入 AIKit 轻量版语音合成实战
android·交互·多语种·离线合成·多种发音人
『 时光荏苒 』1 天前
SQL 中常用的查询条件分类汇总,每个都配有“大白话注释”和示例,方便你对照学习
android·java·开发语言
智购科技自动贩卖机1 天前
自动售货机SaaS多租户数据库实战:分库分表与租户隔离~YH
android·java·linux·开发语言·javascript·网络
遥不可及zzz1 天前
Android 接入 Helpshift SDK 详细教程(Java 实战):客服聊天、FAQ、用户登录及消息推送
android·helpshift