展会信息港展会大全

HorizontalScrollView水平滚动视图的显示
来源:互联网   发布日期:2015-10-03 10:53:44   浏览:1125次  

导读:鸀现效果如下:脀麉现上面这种水平视图滚动,要用到HorizontalScrollView,下面是定义xml文件: <HorizontalScrollView ...

实现效果如下:

要实现上面这种水平视图滚动,要用到HorizontalScrollView,下面是定义xml文件:

<HorizontalScrollView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:scrollbars="none"

android:layout_alignParentBottom="true"

>

<LinearLayout

android:id="@+id/multiselect_path"

android:orientation="horizontal"

android:layout_width="match_parent"

android:layout_height="match_parent">

</LinearLayout>

</HorizontalScrollView>

另外需要一个layout.xml文件定义显示的内容:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

<ImageView

android:id="@+id/multi_icon"

android:layout_height="wrap_content"

android:layout_width="wrap_content"/>

<TextView

android:id="@+id/multi_text"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:paddingLeft="4dip"

android:paddingRight="4dip"

android:maxLength="15"

android:textAppearance="?android:attr/textAppearanceSmall"/>

</LinearLayout>

定义一个MutiSelectHandler类,通过Inflater转化到layout.xml中,构建函数返回一个view对象:

public View addFile(String file) {

view = mInflater.inflate(R.layout.multiselect_layout, null);

ImageView image = (ImageView) view.findViewById(R.id.multi_icon);

TextView text = (TextView) view.findViewById(R.id.multi_text);

if (new File(file).isDirectory()) {

text.setText(file.substring(file.lastIndexOf("/") + 1,

file.length()));

image.setImageResource(R.drawable.folder_md);

} else {

text.setText(file.substring(file.lastIndexOf("/") + 1,

file.length()));

image.setImageResource(R.drawable.text_md);

}

mFileList.add(file);

return view;

}

在操作界面只需要在触发事件中调用addFile函数即可,将返回的view添加到LinearLayout中,就能实现了。

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
展开

热门栏目HotCates

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