.语法获取view的x,y宽高

本文介绍了一个针对UIView类的Objective-C扩展,通过该扩展可以更方便地设置和获取UIView的各种位置及尺寸属性,如x、y坐标,宽度、高度等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#import <UIKit/UIKit.h>

//.h 

@interface UIView (Extension)


@property(nonatomic,assign)CGFloat x;

@property(nonatomic,assign)CGFloat y;

@property(nonatomic,assign)CGFloat centerX;

@property(nonatomic,assign)CGFloat centerY;

@property(nonatomic,assign)CGFloat width;

@property(nonatomic,assign)CGFloat height;

@property(nonatomic,assign)CGSize size;

@property(nonatomic,assign)CGPoint origin;


@end


//.m

#import "UIView+Extension.h"


@implementation UIView (Extension)


-(void)setX:(CGFloat)x {

    

    CGRect frame = self.frame;

    frame.origin.x = x;

    self.frame = frame;

}


-(CGFloat)x {

    return self.frame.origin.x;

}




-(void)setY:(CGFloat)y {

    

    CGRect frame = self.frame;

    frame.origin.y = y;

    self.frame = frame;

    

    

}


-(CGFloat)y {

    return self.frame.origin.y;

    

}



- (void)setCenterX:(CGFloat)centerX

{

    CGPoint center = self.center;

    center.x = centerX;

    self.center = center;

}


- (CGFloat)centerX

{

    return self.center.x;

}


- (void)setCenterY:(CGFloat)centerY

{

    CGPoint center = self.center;

    center.y = centerY;

    self.center = center;

}


- (CGFloat)centerY

{

    return self.center.y;

}



-(void)setWidth:(CGFloat)width {

    

    CGRect frame = self.frame;

    frame.size.width = width;

    self.frame = frame;


}


-(CGFloat)width {

    

    return self.frame.size.width;

    

}


- (void)setHeight:(CGFloat)height

{

    CGRect frame = self.frame;

    frame.size.height = height;

    self.frame = frame;

}


- (CGFloat)height

{

    return self.frame.size.height;

}



- (void)setSize:(CGSize)size

{

    CGRect frame = self.frame;

    frame.size = size;

    self.frame = frame;

}


- (CGSize)size

{

    return self.frame.size;

}


- (void)setOrigin:(CGPoint)origin

{

    CGRect frame = self.frame;

    frame.origin = origin;

    self.frame = frame;

}


- (CGPoint)origin

{

    return self.frame.origin;

}




@end



with temp as ( select case when apply_dept='0303' then '0303' else apply_dept_hs end VISIT_DEPT ,apply_doctor DOCTOR_CODE ,d.idcard idcard ,case when c.s_date is not null and charge_code<>'023758' and gh.ampm is null then a.charge_amount*a.herbal_amount end as 节假日门诊人次 ,case when c.s_date is not null and charge_code<>'023758' and gh.ampm is null then a.charge_price*a.charge_amount*a.herbal_amount end as 节假日诊查费 ,case when c.s_date is not null and charge_code='023758' and gh.ampm is null then a.charge_amount*a.herbal_amount end as 节假日急诊人次 ,case when c.s_date is not null and charge_code='023758' and gh.ampm is null then a.charge_price*a.charge_amount*a.herbal_amount end as 节假日急诊诊查费 ,case when c.s_date is null and charge_code<>'023758' and gh.ampm is null then a.charge_amount*a.herbal_amount end as 非节假日门诊人次 ,case when c.s_date is null and charge_code<>'023758' and gh.ampm is null then a.charge_price*a.charge_amount*a.herbal_amount end as 非节假日诊查费 ,case when c.s_date is null and charge_code='023758' and gh.ampm is null then a.charge_amount*a.herbal_amount end as 非节假日急诊人次 ,case when c.s_date is null and charge_code='023758' and gh.ampm is null then a.charge_price*a.charge_amount*a.herbal_amount end as 非节假日急诊诊查费 ,case when gh.ampm is not null then a.charge_amount*a.herbal_amount else 0 end as 夜诊人次 ,case when gh.ampm is not null then a.charge_price*a.charge_amount*a.herbal_amount else 0 end as 夜诊金额 --增加互联网病人就诊数 ,0 as 互联网人次数 ,0 as 互联网诊察费 from v_mz_detail a join VIEW_MZ_VISIT b on a.p_id=b.p_id and a.times=b.times left join sys_holiday c on trunc(charge_date)=trunc(s_date) left join gh_base gh on trunc(gh.request_date)=trunc(b.VISIT_DATE) and gh.doctor_code=apply_doctor and gh.ampm='y' left join dic_doctor d on a.APPLY_DOCTOR=d.doctsn where a.charge_code in (select charge_code from gh_zd_clinic_charge union all select code from wj_charge_item where code in ( '158285', '158288', '023745', '023746', '023747', '023748', '920738' ) ) and charge_status<>1 and a.bill_code='2' and report_date>=to_date('20250701','yyyymmdd') AND report_date<to_date('20250703','yyyymmdd') and (exists (select 1 from gh_base gh where trunc(gh.request_date)=trunc(b.VISIT_DATE) and gh.doctor_code=apply_doctor ) or apply_dept_hs like '0115%' ) union all select case when g.dept_sn='0303' then '0303' else g.dept_sn_hs end VISIT_DEPT ,y.DOCTOR_CODE DOCTOR_CODE ,d.idcard idcard ,case when c.s_date is not null and charge_code<>'023758' and g.AMPM<>'y' then x.charge_amount end as 节假日门诊人次 ,case when c.s_date is not null and charge_code<>'023758' and g.AMPM<>'y' then x.charge_price*x.charge_amount end as 节假日诊查费 ,case when c.s_date is not null and charge_code='023758' and g.AMPM<>'y' then x.charge_amount end as 节假日急诊人次 ,case when c.s_date is not null and charge_code='023758' and g.AMPM<>'y' then x.charge_price*x.charge_amount end as 节假日急诊诊查费 ,case when c.s_date is null and charge_code<>'023758' and g.AMPM<>'y' then x.charge_amount end as 非节假日门诊人次 ,case when c.s_date is null and charge_code<>'023758' and g.AMPM<>'y' then x.charge_price*x.charge_amount end as 非节假日诊查费 ,case when c.s_date is null and charge_code='023758' and g.AMPM<>'y' then x.charge_amount end as 非节假日急诊人次 ,case when c.s_date is null and charge_code='023758' and g.AMPM<>'y' then x.charge_price*x.charge_amount end as 非节假日急诊诊查费 ,case when g.AMPM='y' then x.charge_amount else 0 end as 夜诊人次 ,case when g.AMPM='y' then x.charge_price*x.charge_amount else 0 end as 夜诊金额 --增加互联网病人就诊数 ,CASE WHEN g. CLINIC_TYPE in ('0P','0Q','6P','2P','3P','4P','5P') THEN x.charge_amount end as 互联网人次数 ,CASE WHEN g. CLINIC_TYPE in ('0P','0Q','6P','2P','3P','4P','5P') THEN x.charge_price*x.charge_amount end as 互联网诊察费 from VIEW_GH_DETAIL x join v_mz_visit y on x.p_id=y.p_id and x.times=y.times and x.CHARGE_AMOUNT>0 join gh_base_child gb on x.P_ID=gb.p_id and x.TIMES=gb.times join v_gh_base_zh g on g.request_sn=gb.request_sn left join dic_doctor d on y.doctor_code=d.doctsn left join sys_holiday c on trunc(advice_time)=trunc(s_date) where x.bill_code='2' and x.charge_code in (select charge_code from gh_zd_clinic_charge union all select code from wj_charge_item where code in ( '158285', '158288', '023745', '023746', '023747', '023748', '920738' ) ) and gb.charge_flag='1' ------已缴费 and nvl(gb."COMMENT",' ') not LIKE '%转诊,作废原明细%' ------转诊有两条记录,排除转诊前原挂号记录 and g.dept_sn not IN ('0305','030501','030504','03060301','030601','070101','0707','9901','0616') and advice_time>=to_date('20250701','yyyymmdd') AND advice_time<to_date('20250703','yyyymmdd') and not exists ( select 1 from GH_DEPOSIT de where de.p_id=x.P_ID and de.times=x.TIMES and de.account_sn=x.ACCOUNT_SN and de.detail_sn=x.DETAIL_SN and de.jzdw='1386') union all select case when g.dept_sn='0303' then '0303' else g.dept_sn_hs end VISIT_DEPT ,y.DOCTOR_CODE DOCTOR_CODE ,d.idcard idcard ,case when c.s_date is not null and charge_code<>'023758' and g.AMPM<>'y' then x.charge_amount end as 节假日门诊人次 ,case when c.s_date is not null and charge_code<>'023758' and g.AMPM<>'y' then x.charge_price*x.charge_amount end as 节假日诊查费 ,case when c.s_date is not null and charge_code='023758' and g.AMPM<>'y' then x.charge_amount end as 节假日急诊人次 ,case when c.s_date is not null and charge_code='023758' and g.AMPM<>'y' then x.charge_price*x.charge_amount end as 节假日急诊诊查费 ,case when c.s_date is null and charge_code<>'023758' and g.AMPM<>'y' then x.charge_amount end as 非节假日门诊人次 ,case when c.s_date is null and charge_code<>'023758' and g.AMPM<>'y' then x.charge_price*x.charge_amount end as 非节假日诊查费 ,case when c.s_date is null and charge_code='023758' and g.AMPM<>'y' then x.charge_amount end as 非节假日急诊人次 ,case when c.s_date is null and charge_code='023758' and g.AMPM<>'y' then x.charge_price*x.charge_amount end as 非节假日急诊诊查费 ,case when g.AMPM='y' then x.charge_amount else 0 end as 夜诊人次 ,case when g.AMPM='y' then x.charge_price*x.charge_amount else 0 end as 夜诊金额 --增加互联网病人就诊数 ,CASE WHEN g. CLINIC_TYPE in ('0P','0Q','6P','2P','3P','4P','5P') THEN x.charge_amount end as 互联网人次数 ,CASE WHEN g. CLINIC_TYPE in ('0P','0Q','6P','2P','3P','4P','5P') THEN x.charge_price*x.charge_amount end as 互联网诊察费 from VIEW_GH_DETAIL x join v_mz_visit y on x.p_id=y.p_id and x.times=y.times and x.CHARGE_AMOUNT<0 join gh_base_child gb on x.P_ID=gb.p_id and x.TIMES=gb.times join v_gh_base_zh g on g.request_sn=gb.request_sn left join dic_doctor d on y.doctor_code=d.doctsn left join sys_holiday c on trunc(advice_time)=trunc(s_date) where x.bill_code='2' and x.charge_code in (select charge_code from gh_zd_clinic_charge union all select code from wj_charge_item where code in ( '158285', '158288', '023745', '023746', '023747', '023748', '920738' ) ) and gb.charge_flag='1' ------已缴费 and nvl(gb."COMMENT",' ') LIKE '%退号%' ------退号 and nvl(gb."COMMENT",' ') not LIKE '%转诊,作废原明细%' ------转诊有两条记录,排除转诊前原挂号记录 and g.dept_sn not IN ('0305','030501','030504','03060301','030601','070101','0707','9901','0616') and case when x.charge_date<ADVICE_TIME then advice_time else x.charge_date end>=to_date('20250701','yyyymmdd') AND case when x.charge_date<ADVICE_TIME then advice_time else x.charge_date end<to_date('20250703','yyyymmdd') and not exists ( select 1 from GH_DEPOSIT de where de.p_id=x.P_ID and de.times=x.TIMES and de.account_sn=x.ACCOUNT_SN and de.detail_sn=x.DETAIL_SN and de.jzdw='1386') ) select decode(grouping(aa.visit_dept),1,'',aa.visit_dept) as 科室编码, decode(grouping(aa.visit_dept)+grouping(bb.name),2,'总合计:',1,bb.name||'小计:',bb.name) as 科室, decode(grouping(cc.name),1,'',cc.name) as 开方医生, decode(grouping(aa.DOCTOR_CODE),1,'',aa.DOCTOR_CODE) as 医生工号, decode(grouping(aa.idcard),1,'',aa.idcard) as 医生身份证, sum(nvl(aa.节假日门诊人次,0)) as 节假日门诊人次, sum(nvl(aa.节假日诊查费,0)) as 节假日诊查费, sum(nvl(aa.节假日急诊人次,0)) as 节假日急诊人次, sum(nvl(aa.节假日急诊诊查费,0)) as 节假日急诊诊查费, sum(nvl(aa.非节假日门诊人次,0)) as 非节假日门诊人次, sum(nvl(aa.非节假日诊查费,0)) as 非节假日诊查费, sum(nvl(aa.非节假日急诊人次,0)) as 非节假日急诊人次, sum(nvl(aa.非节假日急诊诊查费,0)) as 非节假日急诊诊查费 ,sum(nvl(aa.夜诊人次,0)) as 夜诊人次 ,sum(nvl(aa.夜诊金额,0)) as 夜诊金额 --增加互联网病人就诊数 ,sum(nvl(aa.互联网人次数,0)) as 互联网人次数 ,sum(nvl(aa.互联网诊察费,0)) as 互联网诊察费 from temp aa left join dic_dept_code bb on aa.visit_dept=bb.dept_sn left join dic_employee cc on aa.DOCTOR_CODE=cc.emp_sn group by grouping sets((aa.visit_dept,aa.DOCTOR_CODE,idcard, bb.name, cc.name),(),(bb.name)) order by bb.name,aa.visit_dept nulls last; 查询缓慢
最新发布
07-15
<think>好的,我现在需要回答用户关于如何在Android中动态设置布局的X和Y坐标的问题。首先,我需要回忆Android开发中有关视图定位的相关知识。用户提到“programmatically”,也就是以编程方式设置,而不是在XML布局文件中设置。 首先,我应该考虑Android中视图的位置控制方式。常用的方法可能有几种,比如使用setX()和setY()方法,或者通过修改布局参数(LayoutParams)。不过,不同版本的Android可能支持不同的方法,这需要考虑兼容性。 接下来,我需要确认这些方法的正确性。比如,View类确实有setX()和setY()方法,但它们是在API Level 11(Android 3.0)引入的。对于旧版本的支持可能需要使用其他方式,比如设置 margins 或者使用 translationX/Y。但用户的问题中没有提到兼容旧版本,所以可能可以默认使用较新的方法。 外,LayoutParams中的设置可能适用于父布局的类型。例如,如果父布局是RelativeLayout,可以设置leftMargin和topMargin,或者使用类似addRule的方法。而如果是FrameLayout,可能需要使用left和top参数,或者使用setX/Y直接调整视图的位置。 需要注意的是,直接设置X和Y坐标可能会与布局的测量和排列机制产生冲突。例如,如果父布局重新进行布局,可能会导致设置的位置被覆盖。因此,可能需要将视图的位置设置为绝对位置,或者确保在布局过程中不会改变这些值。 用户提供的引用中有提到GenericDraweeHierarchyBuilder的设置,这可能和Fresco库相关,但用户的问题是关于设置坐标,所以可能需要忽略这部分引用。一个引用提到以编程方式打开选择器的选项,这可能与问题无关,但需要确认是否有相关内容可以帮助回答。 接下来,我需要组织回答的结构。首先,明确可以通过setX()和setY()方法直接设置坐标,但需要检查API级别。其次,对于旧版本,可以使用setTranslationX()和setTranslationY(),但这会影响视图的平移而不是绝对位置。外,修改LayoutParams的leftMargin和topMargin也是一种方法,但需要根据父布局的类型来调整。 还需要提到,在Android中,视图的位置通常由布局管理器控制,直接设置坐标可能会影响布局的稳定性,因此需要谨慎使用。可能还需要给出示例代码,比如如何获取View的布局参数并修改,或者直接调用setX/Y方法。 最后,用户可能需要处理的是如何确保设置后的坐标在屏幕上的正确位置,可能需要考虑屏幕密度、单位转换等问题,比如将dp转换为像素。不过用户的问题主要集中在设置方法上,可能暂时不需要深入讨论单位转换。 总结回答步骤: 1. 使用setX()和setY()方法(API 11+)。 2. 使用translationX/Y进行平移。 3. 通过LayoutParams设置边距或其他参数,适用于不同布局类型。 4. 注意事项和兼容性问题。 5. 提供代码示例。 需要验证这些方法的正确性,确保代码示例正确无误,并且语法正确。同时,根据用户提供的引用,可能需要引用相关的Android文档或开发者资源,但用户给出的引用似乎不直接相关,可能不需要引用。</think>在Android中动态设置视图的X和Y坐标可以通过以下方法实现: ### 方法1:使用`setX()`和`setY()`(API Level 11+) 适用于Android 3.0及以上系统: ```java View view = findViewById(R.id.your_view); view.setX(100); // 单位:像素 view.setY(200); ``` 注意需将dp值转换为像素,可使用: ```java float density = getResources().getDisplayMetrics().density; int xPx = (int)(20 * density); // 20dp转像素 view.setX(xPx); ``` ### 方法2:通过布局参数调整(兼容旧版本) 适用于所有API级别,需根据父容器类型选择对应参数: ```java View view = findViewById(R.id.your_view); FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams(); params.leftMargin = xPx; // 相对父容器左边距 params.topMargin = yPx; // 相对父容器顶边距 view.setLayoutParams(params); ``` ### 方法3:使用`setTranslationX()`和`setTranslationY()` 实现视图平移效果(不改变布局参数): ```java view.setTranslationX(50); // 向右平移50像素 view.setTranslationY(-30); // 向上平移30像素 ``` ### 注意事项 1. **坐标系差异**:`setX/Y()`基于父容器坐标系,而`setTranslationX/Y()`是视图当前位置的偏移量 2. **布局冲突**:直接设置坐标可能被父布局的`onLayout()`覆盖,建议在自定义布局中处理 3. **性能优化**:频繁修改坐标时应使用属性动画(如`ObjectAnimator`)而非直接操作
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值