首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

HorizontalScrollView水准滚动视图的显示

2013-10-08 
HorizontalScrollView水平滚动视图的显示实现效果如下: 要实现上面这种水平视图滚动,要用到HorizontalScro

HorizontalScrollView水平滚动视图的显示

  实现效果如下:

 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中,就能实现了。

热点排行