zoukankan      html  css  js  c++  java
  • gridview-selector的设置

    其实它是跟listview相似的,如果你看下它跟listview的继承关系,就很容易理解了

    public class GridView extends AbsListView {
        /**  
         * Disables stretching.
         *
         * @see #setStretchMode(int)
         */
        public static final int NO_STRETCH = 0; 
        /**  
         * Stretches the spacing between columns.
         *
         * @see #setStretchMode(int)
         */
        public static final int STRETCH_SPACING = 1; 
        /**  
         * Stretches columns.
         *
         * @see #setStretchMode(int)
         */
        public static final int STRETCH_COLUMN_WIDTH = 2; 
        /**  
         * Stretches the spacing between columns. The spacing is uniform.
         *
         * @see #setStretchMode(int)
         */
        public static final int STRETCH_SPACING_UNIFORM = 3; 
    
    }

    而且,它里面并没有selector的方法,那我们继续看AbListView这个类

    public abstract class AbsListView extends AdapterView<ListAdapter> implements TextWatcher,
            ViewTreeObserver.OnGlobalLayoutListener, Filter.FilterListener,
            ViewTreeObserver.OnTouchModeChangeListener,
            RemoteViewsAdapter.RemoteAdapterConnectionCallback {
    
    
     public void setSelector(int resID) {
            setSelector(getResources().getDrawable(resID));
        }  
    
        public void setSelector(Drawable sel) {  
            if (mSelector != null) {
                mSelector.setCallback(null);
                unscheduleDrawable(mSelector);           
            }
            mSelector = sel;
            Rect padding = new Rect();
            sel.getPadding(padding);
            mSelectionLeftPadding = padding.left;    
            mSelectionTopPadding = padding.top;      
            mSelectionRightPadding = padding.right;  
            mSelectionBottomPadding = padding.bottom;
            sel.setCallback(this);
            updateSelectorState();
        }  
    
    
    
    
    }

    可以看到它里面是有这个方法的。

    在xml中设定的方法如下

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ll_share_flipper"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    
        <GridView
            android:id="@+id/gv_share_gridview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:hapticFeedbackEnabled="true"
    <!--跟listview的使用方法一样-->
    android:listSelector
    ="@drawable/gridview_selector" android:numColumns="4" android:scrollbars="none" android:stretchMode="columnWidth" > </GridView> </LinearLayout>
  • 相关阅读:
    JFinal项目eclipse出现the table mapping of model: com.gexin.model.scenic.Scenic not exists or the ActiveRecordPlugin not start.
    mysql图形化工具获取表的源码
    数据库中字段是什么意思?
    myeclipse出现Failed to load JavaHL Library.
    1002.查找常用字符
    JS中的AO 和 VO 闭包
    制作icon图标
    babel
    递归时间复杂度
    js函数的柯里化和偏函数
  • 原文地址:https://www.cnblogs.com/zhangshuli-1989/p/zhangshuli_selector_150313172.html
Copyright © 2011-2022 走看看