想实现左右拖动ImageView或TextView的效果,于是参考了一位高手的实现过程,总结了一下。高手的博客:http://marshal.easymorse.com/archives/3029
1、先要在配置文件中用到的地方配置:
这里就只显示一行,以便左右拖动。其中android:scrollbars="none"是去掉滚动条的。
2、在代码中初始化并向TableRow中添加View:
这儿演示了添加ImageView。
1、先要在配置文件中用到的地方配置:
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="48dip"
android:scrollbars="none">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="48dip">
<TableRow
android:id="@+id/row"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</TableLayout>
</HorizontalScrollView>
这里就只显示一行,以便左右拖动。其中android:scrollbars="none"是去掉滚动条的。
2、在代码中初始化并向TableRow中添加View:
TableRow row=(TableRow) this.findViewById(R.id.row);
for (int i=0;i<8;i++){
ImageView imageView=new ImageView(this);
imageView.setImageResource(R.drawable.t1);
row.addView(imageView);
}
这儿演示了添加ImageView。