`

用ScrollView和TableLayout实现类似于Gallery的效果

 
阅读更多
想实现左右拖动ImageView或TextView的效果,于是参考了一位高手的实现过程,总结了一下。高手的博客:http://marshal.easymorse.com/archives/3029
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。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics