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

相关推荐
YF021122 分钟前
Android 16系统App开机自启动方案
android
hm宋1 小时前
安卓手机卡顿优化 —— 背景与使用指南
android
OxYGC2 小时前
[Android] [WatchOS]智能手表第一篇: 实用工具与应用推荐
android·智能手表
嘟哩DuliDuli3 小时前
创作 Agent 的任务状态该如何保存
android·java·javascript
Godikov4 小时前
两个 SDK 抢一个摄像头:Android 设备上的相机仲裁设计与踩坑实录
android
Godikov4 小时前
摄像头电机自动校准实战:为什么我用「步数计数」替换了角度传感器绝对定位
android
Godikov4 小时前
2GB 内存的 Android 工业终端上,我们是怎么把 OOM 按在地上摩擦的
android
Godikov4 小时前
暗光下摄像头"见鬼"了:一个 2GB 内存 Android 终端的帧差唤醒踩坑记
android