滚动菜单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\[\]中的数据足够的,超出屏幕即可滑动查看

相关推荐
哆啦A梦z8 分钟前
Android BLE 实战:从小米手环 7 踩坑到完整连接框架
android
笑一下蒜了.1 小时前
Linux 存储多路径访问手册|multipath.conf 各配置段详解
android·linux·运维
凡泰AI1 小时前
如何通过小程序多端框架,让一个小程序同时运行在iOS、安卓、鸿蒙以及PC客户端,实现一次开发多端运行的效果
android·ios·小程序
一笑的小酒馆2 小时前
Androidiot扫地机器人设备详情页地图加载慢卡顿优化方案
android
xixiaoyunya2 小时前
安卓远程管理电脑/NAS文件:从传统SMB方案到Web化私有云的选型与落地实践
android·电脑
Zhu7587 小时前
在k8s集群部署MySQL单实例,支持多个主流发行版
android·mysql·kubernetes
AFinalStone10 小时前
Android 7系统异常问题排查(四)Framework层(上)—System Server Watchdog
android·系统异常
宝杰X712 小时前
Android Room3 多平台数据库
android·数据库
huibin14785236915 小时前
热缓解学习记录
android·学习
小田的博客18 小时前
SAP MM 供应商银行主数据更新报错!message R1228!
android·java·服务器