欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

讓GridView擁有Gallery的拖動功能

系統 1704 0
利用Gallery的拖動功能,能很容易的將在一行上顯示不下的內容顯示出來。
這種特性可以用在菜單上(如果菜單足夠多,以至一行顯示不下)。
但是Gallery有個不爽的地方,就是被點擊的那個item會一直出現在中間,有時候我們并不需要這樣的“智能”!怎么辦呢?
那就利用GridView,將GridView放在HorizontalScrollView中,如下:
    
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
  	android:orientation="vertical"
  	android:layout_width="fill_parent"
  	android:layout_height="fill_parent">

   	<RelativeLayout android:background="#030e13"
    	android:layout_width="fill_parent"
    	android:layout_height="wrap_content"
	    >
	    <ImageView android:id="@+id/webnav_left" 
	        android:layout_width="8dip"
	        android:layout_height="wrap_content"
	        android:layout_centerVertical="true"
	        android:src="@drawable/news_left"
			/>
	    <ImageView android:id="@+id/webnav_right" 
	        android:layout_width="8dip"
	        android:layout_height="wrap_content"
    		android:layout_alignParentRight="true"
	        android:layout_centerVertical="true"
	        android:src="@drawable/news_right"
			/>
		<HorizontalScrollView android:layout_width="fill_parent"
	        android:layout_height="wrap_content"
       		android:layout_toLeftOf="@id/webnav_right"
       		android:layout_toRightOf="@id/webnav_left"
	        android:scrollbars="none">
	        <LinearLayout android:layout_width="fill_parent"
	            android:layout_height="wrap_content">
	            <LinearLayout android:id="@+id/layout_webnav" 
	            	android:layout_width="800dip"
	                android:layout_height="wrap_content"
	                android:orientation="horizontal"> 
				  	<GridView android:id="@+id/gallery_webnav" 
						android:layout_width="fill_parent"
						android:layout_height="fill_parent"
						android:background="#030e13"
				        android:gravity="center" 
				        android:numColumns="auto_fit"
				        android:listSelector="#00000000">
				    </GridView> 
	    		</LinearLayout>
	        </LinearLayout>
	    </HorizontalScrollView>
  	</RelativeLayout>

</LinearLayout>

  

注意上面id為layout_webnav的LinearLayout,這里的layout_width是需要計算的!見下面代碼。
    
public class Test_2_Activity  extends Activity{

	private final int per=3;//每行顯示的個數
	private GridView gridView;
	 @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.test2);
	        DisplayMetrics dm = new DisplayMetrics();
	        dm = getApplicationContext().getResources().getDisplayMetrics();
	        int menuWidth = dm.widthPixels-16;
	        
	        gridView= (GridView) findViewById(R.id.gallery_webnav); 
	        int itemWidth = menuWidth/per;
	        gridView.setColumnWidth(itemWidth);
	        
	        ArrayList<Map<String,String>> data=new ArrayList<Map<String,String>>();
	        Map<String,String> map;
	        for(int i=0;i<5;i++){
	        	map=new HashMap<String,String>();
	        	map.put("simple_item_1", "name"+i);
	        	map.put("simple_item_2", "age"+i);
	        	map.put("simple_item_3", "class"+i);
	        	data.add(map);
	        }
	        int resource=R.layout.row_test2;
	        String[] from={"simple_item_1","simple_item_2","simple_item_3"};
	        int[] to={R.id.simple_item_1,R.id.simple_item_2,R.id.simple_item_3};
	        SimpleAdapter adapter=new SimpleAdapter(this, data, resource, from, to);
	        
	        gridView.setAdapter(adapter);
	        
	      //讓GridView一行顯示,這里的layout_width是需要計算的
	        LinearLayout layout = (LinearLayout) findViewById(R.id.layout_webnav); 
	        layout.setLayoutParams(new LayoutParams(itemWidth*data.size(), LayoutParams.WRAP_CONTENT));
	        
	        gridView.setSelection(0);
                gridView.setOnItemClickListener(listener);
	 }
}

  

注意上面的itemWidth*data.size(),這里才是LinearLayout的實際寬度!

R.layout.row_test2布局如下:
    
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
  	<TextView android:id="@+id/simple_item_1"
	    android:layout_width="fill_parent" 
	    android:layout_height="fill_parent" 
	    android:gravity="center"
	    />
    <RelativeLayout android:background="#030e13"
    	android:layout_width="fill_parent"
    	android:layout_height="fill_parent"
	    >
	    <TextView android:id="@+id/simple_item_2"
	    android:layout_width="wrap_content" 
	    android:layout_height="wrap_content" 
	    android:layout_alignParentLeft="true"
	    android:paddingLeft="10dp"
	    />
	    <TextView android:id="@+id/simple_item_3"
	    android:layout_width="wrap_content" 
	    android:layout_height="wrap_content" 
	    android:layout_alignParentRight="true"
	    android:paddingRight="10dp"
	    />
	</RelativeLayout>
</LinearLayout>

  

運行后顯示的效果:


看不出什么,呵呵,拖動一下看看。


讓GridView擁有Gallery的拖動功能


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 久久久国产一区 | 国产精品福利片免费看 | 久久九九精品一区二区 | 欧美精品第三页 | 欧美成人18 | 精品视频一区二区 | 看特级毛片 | 精品伊人久久 | 国产日韩欧美亚洲 | 亚洲香蕉毛片久久网站老妇人 | 久久久久久久免费视频 | 国精品日韩欧美一区二区三区 | 色婷婷影院 | 图片区乱熟图片区小说 | 国产精品久久久久无码av | 日本精品久久久一区二区三区 | 九九福利影院 | 色综合久久88中文字幕 | 色狠狠色狠狠综合一区 | 国产一级特黄aa大片爽爽 | 欧美9999| 波多野结衣在线看片 | 亚洲色图150p | 观看av| 黄色一级a毛片 | 日韩日日操 | 永久精品| 极品狂兵电视剧免费观看 | 夜夜爽日日澡人人 | 久久精品免费一区二区三区 | 在线视频 中文字幕 | 欧美偷偷操| 成人国产精品免费观看视频 | 麻豆视频秘密入口 | 国产一区二区三区视频 | 欧美另类视频一区二区三区 | 国产亚洲精品久久久久久久网站 | 国产乱仑| 日韩在线观看中文字幕 | 亚洲欧美日本在线 | 欧美三级美国一级 |