我怎么能做这样的事情?
抽屉导航内的两个可扩展 ListView 。我试图将它添加到我的 xml 中,但没有成功。 我想要的是只有一个滚动条的 View ,但我不知道该怎么做..
这是我的抽屉式导航布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/Bianco"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginRight="16dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/tvHomeActions"
android:id="@+id/textView" />
<ExpandableListView
android:id="@+id/elvHome"
android:layout_width="match_parent"
android:layout_marginTop="4dp"
android:layout_height="300dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/tvHomeNavigations"
android:layout_marginTop="16dp"
android:id="@+id/textView2" />
<ExpandableListView
android:id="@+id/elvNavigateTo"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="4dp" />
</LinearLayout>
</ScrollView>
编辑: 我想在 Gmail 应用程序中创建类似抽屉的东西
最佳答案
我终于明白了! 这是我创建的代码,用于获取带有部分标题的 ExpandableListView。 现在我可以轻松地为标题、组和子项创建三个 xml 自定义布局。
它对我有用,但我接受任何代码改进以优化内存使用、速度等。
// ---------------------------------------------------------------------------------------------
// NAVIGATION DRAWER SIDE FRAGMENT
// ---------------------------------------------------------------------------------------------
private ExpandableListView mDrawerListView;
private List<Elemento> mainActions = new ArrayList<>();
private HashMap<Integer, List<String>> childActions = new HashMap<>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.frg_navigation_drawer, container, false);
assert v != null;
mDrawerListView = (ExpandableListView) v.findViewById(R.id.elvHome);
mDrawerListView.setGroupIndicator(null);
// add first title
mainActions.add(new TitoloGruppo("Good guys")); // 0
mainActions.add(new Azione("Admiral Ackbar", "Dagobah System")); // 1
mainActions.add(new Azione("Han Solo", "Millenium Falcon")); // 2
mainActions.add(new Azione("Yoda", "Dagobah System")); // 3
// add second title
mainActions.add(new TitoloGruppo("Bad guys")); // 4
mainActions.add(new Azione("Emperor", "Death star 2")); // 5
mainActions.add(new Azione("Jabba", "Tatooine")); // 6
mainActions.add(new Azione("Grand Moff Tarkin", "Death star 1")); // 7
// Adding child quotes to Ackbar
List<String> mainSubFive = new ArrayList<>();
mainSubFive.add("It's a trap!");
// Adding child quotes to Yoda
List<String> mainSubThree = new ArrayList<>();
mainSubThree.add("Do or do not; there is no try.");
mainSubThree.add("There is … another … Sky … walker.…");
mainSubThree.add("When 900 years old you reach, look as good you will not ehh.");
childActions.put(0, new ArrayList<String>());
childActions.put(1, mainSubFive);
childActions.put(2, new ArrayList<String>());
childActions.put(3, mainSubThree);
childActions.put(4, new ArrayList<String>());
childActions.put(5, new ArrayList<String>());
childActions.put(6, new ArrayList<String>());
mDrawerListView.setAdapter(new ExpandableAdapter(getActivity(), mainActions, childActions));
mDrawerListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
List<String> list = childActions.get(groupPosition);
if(list.size() > 0)
return false;
else
Toast.makeText(getActivity(), ""+ ((Azione) mainActions.get(groupPosition)).getSubtitle(), Toast.LENGTH_LONG).show();
return false;
}
});
mDrawerListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
List<String> list = childActions.get(groupPosition);
Toast.makeText(getActivity(), "" + list.get(childPosition).toString(), Toast.LENGTH_LONG).show();
return false;
}
});
return v;
}
// ---------------------------------------------------------------------------------------------
// INTERNAL CLASS
// ---------------------------------------------------------------------------------------------
protected class ExpandableAdapter extends BaseExpandableListAdapter {
private Context context;
private List<Elemento> mainElements;
private HashMap<Integer, List<String>> childElements;
private LayoutInflater vi;
public ExpandableAdapter(Context context, List<Elemento> mainElements, HashMap<Integer, List<String>> childElements) {
this.context = context;
this.mainElements = mainElements;
this.childElements = childElements;
vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getGroupCount() {
return this.mainElements.size();
}
@Override
public int getChildrenCount(int groupPosition) {
if(this.childElements.get(groupPosition) == null)
return 0;
return this.childElements.get(groupPosition).size();
}
@Override
public Object getGroup(int groupPosition) {
return this.mainElements.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return this.childElements.get(groupPosition).get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = convertView;
final Elemento i = mainElements.get(groupPosition);
if (i != null) {
if(i.isGroupSection()){
final TitoloGruppo si = (TitoloGruppo)i;
v = vi.inflate(android.R.layout.simple_list_item_1, null);
v.setOnClickListener(null);
v.setOnLongClickListener(null);
v.setLongClickable(false);
final TextView sectionView = (TextView) v.findViewById(android.R.id.text1);
sectionView.setTextColor(Color.parseColor("#FFC800"));
sectionView.setText(si.getTitle());
}else if(i.isAction()){
Azione ei = (Azione)i;
v = vi.inflate(android.R.layout.simple_list_item_2, null);
final TextView title = (TextView)v.findViewById(android.R.id.text1);
final TextView subtitle = (TextView)v.findViewById(android.R.id.text2);
if (title != null)
title.setText(ei.title);
if(subtitle != null)
subtitle.setText("count: " + getChildrenCount(groupPosition));
}
}
return v;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(android.R.layout.simple_list_item_1, null);
}
TextView txtListChild = (TextView) convertView.findViewById(android.R.id.text1);
txtListChild.setText(childText);
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
public class TitoloGruppo implements Elemento {
private final String titolo;
public TitoloGruppo(String titolo) {
this.titolo = titolo;
}
public String getTitle(){
return titolo;
}
@Override
public boolean isGroupSection() {
return true;
}
@Override
public boolean isAction() {
return false;
}
}
protected interface Elemento {
public boolean isGroupSection();
public boolean isAction();
}
protected class Azione implements Elemento {
public final String title;
public final String subtitle;
public Azione(String title, String subtitle) {
this.title = title;
this.subtitle = subtitle;
}
public String getTitle() {
return this.title;
}
public String getSubtitle() {
return this.subtitle;
}
@Override
public boolean isGroupSection() {
return false;
}
@Override
public boolean isAction() {
return true;
}
}
附言。谢谢大家
关于Android:抽屉导航内有 2 个或更多 ExpandableListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21112832/
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
为了在我的mac上为一个rails项目安装mysql,我遵循了安装Homebrew软件和删除mac端口的在线建议。这是问题开始的地方。rails项目不会构建,我得到这个:[rake--prereqs]rakeaborted!dlopen(/Users/Parker/.rvm/gems/ruby-1.9.3-p448/gems/nokogiri-1.6.0/lib/nokogiri/nokogiri.bundle,9):Librarynotloaded:/opt/local/lib/libiconv.2.dylibReferencedfrom:/Users/Parker/.rvm/gem
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。我最近开始学习Ruby,这是我的第一门编程语言。我对语法感到满意,并且我已经完成了许多只教授相同基础知识的教程。我已经写了一些小程序(包括我自己的数组排序方法,在有人告诉我谷歌“冒泡排序”之前我认为它非常聪明),但我觉得我需要尝试更大更难的东西来理解更多关于Ruby.关于如何执行此操作的任何想法?
在部署在heroku上的Rails应用程序(v:3.1)中,我在内存中获得了更多具有相同ID的对象。我的heroku控制台日志:>>Project.find_all_by_id(92).size=>2>>ActiveRecord::Base.connection.execute('select*fromprojectswhereid=92').to_a.size=>1这怎么可能?可能是什么问题? 最佳答案 解决方案根据您的SQL查询,您的数据库中显然没有重复条目。也许您的类项目中的size或length方法已被覆盖。我试过find_
我正在尝试将全局导航菜单项添加到我的ActiveAdmin安装(在“仪表板”导航按钮旁边)。ActiveAdmin说这在他们的网站上是可能的,但他们没有任何关于如何实现它的文档。有谁知道如何做到这一点?编辑:抱歉,我应该更清楚。我想添加一个指向由任意文本/链接对组成的全局导航的链接。IE,如果我想添加一个链接到http://google.com在事件管理员的全局导航中使用文本“Google”,我将如何实现? 最佳答案 ActiveAdmin.register_page"Google"domenu:priority=>1,:label
目标:我想从动画GIF中抓取最佳帧并将其用作静态预览图像。我相信最好的帧是显示最多内容的帧-不一定是第一帧或最后一帧。以这张动图为例:--这是第一帧:--这是第28帧:很明显,第28帧很好地代表了整个GIF。我如何以编程方式确定一帧是否比另一帧具有更多像素/内容?如果您能向我指出任何想法、想法、包/模块或文章,我们将不胜感激。 最佳答案 实现此目的的一种直接方法是估计entropy每个图像的帧,并选择具有最大熵的帧。在信息论中,熵可以被认为是图像的“随机性”。单一颜色的图像是非常可预测的,分布越平坦,越随机。这与Arthur-R描述
伴随农业机械化和智能化的发展,越来越多的人开始使用农机自动驾驶系统助力耕作,千耘农机导航的“星地一体”能力可有效解决信号受限的问题,实现作业提效。究竟什么是“星地一体”,又是如何解决智能化农机作业的痛点的?下面为大家揭秘。农机效率通常受限于通信网络目前虽然我国通讯网络的人口覆盖率达到99%,但地面移动通讯网络覆盖率仍小于国土面积的40%,而很多农田所在区域恰是山区、戈壁滩等偏远地区。两省交界地也会出现通信信号不稳定的状况;而国内大部分农机自动驾驶系统非常依赖通信网络,当通信网络弱的时候会出现系统掉线的现象,必须得携带小基站才能正常使用,极为繁琐。Q:什么是千耘农机导航“星地一体”能力?A:是星
我想要一个名为same_url的方法?如果传入的URL相等,它将返回true。传入的URL可能是参数选项散列或字符串。same_url?({:controller=>:foo,:action=>:bar},"http://www.example.com/foo/bar")#=>trueRails框架助手current_page?似乎是一个很好的起点,但我想传入任意数量的URL。作为一个额外的好处,如果可以传入要从比较中排除的参数的哈希值,那就太好了。因此方法调用可能如下所示:same_url?(projects_path(:page=>2),"projects?page=3",:exc
运行有问题或需要源码请点赞关注收藏后评论区留言一、利用ContentResolver读写联系人在实际开发中,普通App很少会开放数据接口给其他应用访问。内容组件能够派上用场的情况往往是App想要访问系统应用的通讯数据,比如查看联系人,短信,通话记录等等,以及对这些通讯数据及逆行增删改查。首先要给AndroidMaifest.xml中添加响应的权限配置 下面是往手机通讯录添加联系人信息的例子效果如下分成三个步骤先查出联系人的基本信息,然后查询联系人号码,再查询联系人邮箱代码 ContactAddActivity类packagecom.example.chapter07;importandroid
1.前言 在10.0的系统rom定制化开发中,在系统中有多个launcher的时候,会在开机进入launcher的时候弹窗launcher列表,让用户选择进入哪个launcher,这样显得特别的不方便所以产品开发中,要求用RoleManager的相关api来设置默认Launcher,但是在设置完默认Launcher以后,在安装一款Launcher的时候,默认Launcher就会失效,在系统设置的默认应用中Launcher选项就为空,点击home键的时候会弹出默认Launcher列表,让选择进入哪个默认Launcher.所以需要从安装Launcher的流程来分析相关的设置。来解决问题设置默认La