码迷,mamicode.com
首页 > 移动开发 > 详细

Android总结

时间:2017-03-28 19:04:27      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:code   top   title   .com   something   上下文   into   send   har   

经过近几个星期的学习,让我对安卓有了更清晰的认识。对于任务T2的学习,使我对TextView,EditText以及Button三个控件有了初步掌握,虽仍不熟练,但还是有所得益处的。

最起码,我知道了很多以前不知道的界面控件,例如:

Textview控件常用属性:
android:layout_width(设置控件的宽度),android:layout_height(设置控件的高度),android:id(设置组件的ID),android:text(设置文本的内容),android:textColor(设置文本颜色),android:gravity(设置文本相对控件的位置)。
例如:

  <TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:id="@+id/tv1"
   android:text "@string/hello_word"
   android:textSize="18sp":
   android:textColor="#FFFFFF"
   android:backgroud="#0000FF"/>

 Button控件

(1)添加Button控件到XML布局文件中,在布局文件中设置按钮的一些属性,如位置,宽度,按钮上的字,颜色等。比较重要的是给按钮一个ID,这是按钮唯一的名称。

(2)处理按钮的单击事件:通过onclick属性设置处理单击事件的方法名;

public void myclick(View view){
  //Do something in response to button click

}
另一种方法是使用setOnclickListener添加监听器对象:
Button button=(Button)findViewById(R.id.button_send);
button.setOnClickListener(new View.OnClickListener(){

   public void onClick(View v){
   Do something in response to button click
}
 }

ImageView控件
ImageView控件是用于展示图片的控件,可以展示两种图片:一是普通的静态图片;二是动态的图片,如GIF格式的图片。
ImageView控件的常用属性:android:adjustViewBounds(是否保持宽高比),android:src(用于设置ImageView中展示什么图片),android:tint(将图片渲染成指定的颜色)。
其中,属性android:src用于设置ImageView中显示什么图片,如利用ImageView控件实现图片循环浏览的功能:

(1)

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   android:orientation="vertial"
   android:layout_width="fill_parent"
   android:layout_heigth="fill_parent"
   android:gravity="center_horizontal">
   <ImageView
      android:id="@+id/img_showmulti"
      android:layout_width="80dp"
      android:layout_heigth="80dp"
      android:src="@drawable/btml"
      android:layout_gravity="center_horizontal"/>
  <LinearLayout
     android:orientation="vertial"
     android:layout_width="fill_parent"
     android:layout_heigth="fill_parent"
     android:gravity="center_horizontal"
     android:layout_marginTop="20dp">
     <Button
        android:id="@+id/btn_previous"
        android:layout_width="0dp"
        android:layout_heigth="wrap_content"
        android:layout_weight="l"
        android:text="@string/pre"/>
  </LinearLayout>
    </LinearLayout>

(2)定义“上一幅”、“下一幅”按钮的逻辑:

img_photo=(ImageView) findviewById(R.id.img_showmulti);//获取布局中的按钮
Button btn_previous=(Button) findViewById(R.id.btn_previous);
Button btn_next=(Button) findViewById(R.id.btn_next);
btn_previous.setOnClickListener(this);
btn_next.setOnClickListener(this);

再就是上下文菜单,上下文菜单的加载方式有点特殊,那就是必须在onCreate方法中进行注册,并且是给相应的对象进行注册,否则的话就没有任何效果,这是写了一个最简单的上下文菜单:

@Override
    public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, view, menuInfo);
        switch(view.getId()){
            case R.id.name:
                menu.add(0,100,0,"选择");
                break;
        }
    }

然后在onCreate方法中进行注册:

this.registerForContextMenu(et_name);//将上下文菜单注册到姓名的输入框。


虽然就安卓来说,我还没学到多少东西,但是这才只是开始,随着以后的继续学习,我相信我一定能把安卓学好。


Android总结

标签:code   top   title   .com   something   上下文   into   send   har   

原文地址:http://www.cnblogs.com/wangqiandage/p/6636120.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!