安卓:使用XML布局日期选取器 [英] Android: Date Picker using xml layout

查看:175
本文介绍了安卓:使用XML布局日期选取器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用XML code显示日期选择器。但它并没有显示任何内容。我只能通过Java code显示的DatePicker?

I tried to display date picker using xml code. But it did not display anything. Can I display DatePicker only through java code?

public class datePickerExample extends Activity
{
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.date_picker_example); 
    }
}

date_picker_example.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/lay_main"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Date : " >
    </TextView>

    <DatePicker
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:endYear="2100"
        android:startYear="1900" >
    </DatePicker>

</LinearLayout>

感谢您......

推荐答案

添加此属性:

android:orientation="vertical"

在你的LinearLayout元素和日期选择器将出现。

in your LinearLayout element and the date-picker will appear.

这篇关于安卓:使用XML布局日期选取器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆