学习要打好基础,这里用一个项目来学习一下Android的组件,参考网址为这个但不限于这个。有些东西的学习,理解三遍理论还不如一遍操作,所谓理论来自实践,实践是检验真理的唯一标准。所以,虽然看懂了那篇文章,还是自己做一遍来加深理解。

1,cmd下面生成项目

mvn archetype:generate -DarchetypeArtifactId=android-quickstart -DarchetypeGroupId=de.akquinet.android.archetypes -DarchetypeVersion=1.0.11 -DgroupId=com.vanceinfo.android -DartifactId=CAIO

2, 导入项目至Kepler,新建一个类,然后Alt+Shift+S,选择Override/Implement Method, override onCreate(Bundle savedInstanceState),方法内容先不管它,去到项目的AndroidManifest.xml文件中,将<activity android:name=".HelloAndroidActivity" >改为<activity android:name=".SpinnerActivity" >,等下启动时就来到这个组件来显示,接着来到layout的文件夹中,新建一个叫spinner.xml文件,使用Graphic layout,先拖入linearLayout,然后拖一个label,一个spinner,还有一个button共四个组件进来,由eclipse自动为我们生成的xml如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="下拉框1:"
    />

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="150dip"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="false"
    />
    
    <TextView
        android:id="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="下拉框2:"
    />
    
    <Spinner
        android:id="@+id/spinner2"
        android:layout_width="150dip"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="false"
    />
    
    <Button
        android:id="@+id/ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/ok"
    />

</LinearLayout>
layout_linear

相关文章:

  • 2022-12-23
  • 2021-08-25
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2021-08-30
  • 2021-07-27
  • 2021-09-11
相关资源
相似解决方案