改变DatePicker和TimePicker大小,使之横向并列展示

DatePicker和TimePicker的大小被google写死了 在xml中限定大小 更本没用

1.创建一个类 继承FrameLayout ,然后修改FrameLayout的onmeasure方法.

public class MyWrapContentView extends FrameLayout {
public MyWrapContentView(Context context) {
super(context);
}

public MyWrapContentView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public MyWrapContentView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
widthMeasureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.AT_MOST,0);//核心代码
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}


2.使用该控件包裹DatePicker和TimePicker

<cn.schope.lrr.view.MyWrapContentView
android:layout_gravity="center" #此处必需设置居中,外层是Relativelayout就用centerinparent,是LinearLayout便用layoutgravity
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_gravity="center"
android:id="@+id/ll_picker"
android:layout_width="wrap_content"#使用包裹体
android:layout_height="wrap_content"
android:orientation="horizontal">
<DatePicker
android:id="@+id/dp_submit_day"
android:layout_width="wrap_content"#使用包裹体
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<TimePicker
android:layout_width="wrap_content"#使用包裹体
android:layout_height="wrap_content"
android:id="@+id/time_picker"/>
</LinearLayout>
</cn.schope.lrr.view.MyWrapContentView>


3.使用Nineoldandroids开源库中的ViewHelper缩放控件.(V4包的ViewCompat也可)

View ll_picker = view.findViewById(R.id.ll_picker);
ViewHelper.setScaleX(ll_picker,0.8f);//可以随意指定缩小百分比
ViewHelper.setScaleY(ll_picker,0.8f);

如此就可以实现DatePicker和TimePicker横向并列显示了.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值