12.1 學習筆記 html div塊邊框圓角,footer在div影響下沒有在底部解決,android Viewgroup根據xy獲取在子view

7 篇文章 0 订阅

邊框加圓角

<div id="menu_card">
test
</br>
test
</div>

#menu_card {
    margin-bottom: 30px;

    -moz-border-radius: 4px;
    /*Gecko(Firefox内核)浏览器圆角样式*/
    -webkit-border-radius: 4px;
    /*webkit(Chrome内核)浏览器圆角样式*/
    border-radius: 4px;
    /*Trident(IE内核)浏览器圆角样式*/
    /*margin: 10px*/
}

使用了div導致footer沒有在底部顯示,解決辦法:
http://blog.csdn.net/frank0712105003/article/details/38170873
http://ryanfait.com/resources/footer-stick-to-bottom-of-page/

<html>
    <head>
        <link rel="stylesheet" href="layout.css" ... />
    </head>
    <body>
        <div class="wrapper">
            <p>Your website content here.</p>
            <div class="push"></div>
        </div>
        <div class="footer">
            <p>Copyright (c) 2008</p>
        </div>
    </body>
</html>

css:

.footer, .push {
    clear: both;
}

andriod viewgroup中根據xy坐標獲取子view,這個工具能獲取子viewgroup的view(多重都可以獲取,xy是touch event中getX getY獲取的)

/**
 * 視圖工具
 * Created by george.yang on 2015/11/30.
 */
public class ViewUtil {
    /**
     * 根据坐标获取相对应的子控件
     * 在Activity使用
     * @param activity
     * @param x
     * @param y
     * @return
     */
    public static View getViewAtActivity(Activity activity,int x, int y) {
        // 从Activity里获取容器
        ViewGroup root = (ViewGroup) activity.getWindow().getDecorView();
        return getViewAtViewGroup(root,x, y);
    }

    final  static int[] tempXY = new int[2];
    /**
     * 根据坐标获取相对应的子控件<br>
     * 在重写ViewGroup使用
     * @param vg
     * @param x of toucg.getX()
     * @param y of touch.getY()
     * @return
     */
    public static View getViewAtViewGroup(ViewGroup vg,int x, int y) {
        synchronized (tempXY) {
            vg.getLocationInWindow(tempXY);
            return getViewAtViewGroupExec(vg,x,y);
        }
    }

    private static View getViewAtViewGroupExec(ViewGroup vg,int x, int y) {
        View subView = null;
        for (int i=0;i<vg.getChildCount();i++) {
            View view = vg.getChildAt(i);
            if (view instanceof ViewGroup) {
                subView = getViewAtViewGroupExec((ViewGroup)view,x,y);
                if (subView!=null) {
                    break;
                }
            } else {
                if (isPointInViewOnActivity(view,tempXY[0]+x,tempXY[1]+y)) {
                    return view;
                }
            }
        }
        return subView;
    }
    private static boolean isPointInViewOnActivity(View view, int x, int y) {
        int[] winXY = new int[2];
        view.getLocationInWindow(winXY);
        int startX = winXY[0];
        int endX = startX + view.getMeasuredWidth();
        int startY = winXY[1];
        int endY = startY + view.getMeasuredHeight();

        if (x>=startX && x<=endX && y >= startY && y<= endY) {
            return true;
        }
        return false;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值