程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

网格视图项目菜单

发布于2022-05-19 07:43     阅读(1229)     评论(0)     点赞(2)     收藏(3)


我想问一下如何在网格视图项中添加一个菜单(三个点,带有 actionBar 之类的选项)?我需要它看起来类似于 youtube 的移动应用程序视频:它们都有这三个点,其中包含几个选项。我怎样才能做到这一点?

这是代码:

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ListAdapter;

import java.util.ArrayList;

public class teamTasks extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.team_individual_tasks);

    Button btn3 = (Button) findViewById(R.id.addTasks);

    final ArrayList<String> listItemsTasks=new ArrayList<String>();
    final ListAdapter addAdapterTasks = new ArrayAdapter<String>(this, R.layout.custom_box,
            R.id.customBox, listItemsTasks);
    GridView gvtask = (GridView) findViewById(R.id.gvTasks);
    gvtask.setAdapter(addAdapterTasks);

    btn3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            listItemsTasks.add("New Task");
        }
    });
    gvtask.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        }
    });
}
}

布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:text="+"
    android:textSize="20sp"
    android:id="@+id/addTasks"/>

<GridView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/addTasks"
    android:id="@+id/gvTasks"
    android:numColumns="2">
    </GridView>

</RelativeLayout>

自定义 gridView 项:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="120dp"
    android:id="@+id/customBox"/>


解决方案


暂无回答



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.javaheidong.com/blog/article/442853/6c9eb2568aa9d759e85a/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

2 0
收藏该文
已收藏

评论内容:(最多支持255个字符)