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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值