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中,就能實現瞭。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *