展会信息港展会大全

Android ApiDemos示例解析(155):Views->Layouts->ScrollView->3. Internal Selection
来源:互联网   发布日期:2015-10-03 10:54:05   浏览:1164次  

导读:本例为一个自定义的UI控件InternalSelectionView 添加滚动条,InternalSelectionView 可以显示一个矩形列表,矩形的宽度为View的宽度,允许自定义列表的...

本例为一个自定义的UI控件InternalSelectionView 添加滚动条,InternalSelectionView 可以显示一个矩形列表,矩形的宽度为View的宽度,允许自定义列表的行数,矩形的高度为View的高度平分为列表的行数。 参见Android ApiDemos示例解析(118):Views->Focus->4. Internal Selection。

本例在代码中将InternalSelectionView 的高度设为屏幕高度的两倍,确保ScrollView可以滚动:

[java]

InternalSelectionView isv

= new InternalSelectionView(this, 10);

int screenHeight

= getWindowManager().getDefaultDisplay().getHeight();

LinearLayout.LayoutParams llLp = new LinearLayout.LayoutParams(

ViewGroup.LayoutParams.MATCH_PARENT,

2 * screenHeight);// 2x screen height to ensure scrolling

isv.setLayoutParams(llLp);

ll.addView(isv);

InternalSelectionView isv

= new InternalSelectionView(this, 10);

int screenHeight

= getWindowManager().getDefaultDisplay().getHeight();

LinearLayout.LayoutParams llLp = new LinearLayout.LayoutParams(

ViewGroup.LayoutParams.MATCH_PARENT,

2 * screenHeight);// 2x screen height to ensure scrolling

isv.setLayoutParams(llLp);

ll.addView(isv);

ScrollView 自动管理滚动功能,如果它检测到其内部的内容的高度大于屏幕高度,将自动支持滚动功能:

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港