当前位置:操作系统 > 安卓/Android >>

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 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,