十四、Android常用控件使用指南(持续更新)

Shape

圆角矩形shape:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <!-- rectangle表示为矩形 -->

    <!-- 填充的颜色 -->
    <solid android:color="#FAFAFA" />

    <!-- 边框的颜色和粗细 -->
    <stroke
        android:width="1dp"
        android:color="#FAFAFA" />

    <!-- android:radius 圆角的半径 -->
    <corners android:radius="26dp" />

</shape>

RadionButton选中/未选中状态:

radiobutton_selector.xml

<!--seletor-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_artboard_pen_press" android:state_checked="true" />
    <item android:drawable="@drawable/ic_artboard_pen_normal" android:state_checked="false"/>
</selector>

设置

  android:background="@drawable/ic_artboard_pen_selector"
  android:button="@null"

popupwindow显示在view的上方

PopupWindow popupWindow = getPopupWindow();
 int[] point = new int[2];
 v.getLocationOnScreen(point);
 // Get the View's(the one that was clicked in the Fragment) location
 popupWindow.showAsDropDown(v,0,-mContentView.getMeasuredHeight()-v.getMeasuredHeight());


    private PopupWindow getPopupWindow() {
        PopupWindow popupWindow = new PopupWindow();
        mContentView = getLayoutInflater().inflate(R.layout.layout_popupwindow, null);
        popupWindow.setContentView(mContentView);
        mContentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        popupWindow.setHeight(mContentView.getMeasuredHeight());
        popupWindow.setWidth(mContentView.getMeasuredWidth());
        return popupWindow;
    }

在这里插入图片描述
popupwindow的shotAtLocation方法:
主要依据gravity里确定位置(在屏幕中):

   popupWindow.showAtLocation(v,Gravity.CENTER,0,0);//在屏幕中间显示
    popupWindow.showAtLocation(v,Gravity.TOP,0,0);//在屏幕上访显示

在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值