热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Androidxml控件写法和findViewById的对应使用

1.xml控件示例

1.xml控件示例

android:name="@+id/ui_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />

id名称是findviewbyid要寻找的对象,命名严格,书写方式一定要用 "@+id/xxxx"。只有这样,才能在findviewbyid时被找到。

这个是基于android的标准hellowrold工程改写的。完整xml文件如下:

 

 

    package="io.vov.vitamio.demo"

    android:versionCode="002"

    android:versionName="0.0.2" >

 

   

        android:minSdkVersion="7"

        android:targetSdkVersion="19" />

 

   

   

   

   

 

   

        android:allowBackup="false"

        android:icon="@drawable/ic_launcher"

        android:label="@string/vitamio_demo_name" >

 

       

       

            android:name="io.vov.vitamio.activity.InitActivity"

            android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"

            android:launchMode="singleTop"

            android:theme="@android:style/Theme.NoTitleBar"

            android:windowSoftInputMode="stateAlwaysHidden" />

       

           

               

 

               

               

           

       

       

            android:name=".MediaPlayerDemo"

            android:label="Media/MediaPlayer" >

       

       

            android:name=".VideoViewDemo"

            android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"

            android:label="Media/VideoView" >

       

       

            android:name=".MediaPlayerDemo_Video"

            android:label="Media/MediaPlayer" >

       

       

            android:name=".MediaPlayerDemo_setSurface"

            android:label="Media/MediaPlayer" >

       

       

            android:name=".MediaPlayerDemo_Audio"

            android:label="Media/MediaPlayer" >

       

       

            android:name=".MediaMetadataRetrieverDemo"

            android:label="Media/MediaMetadata" >

       

       

            android:name=".MediaPlayerSubtitle"

            android:label="@string/title_activity_media_player_subtitle" >

       

       

            android:name=".VideoViewSubtitle"

            android:label="@string/title_activity_video_view_subtitle" >

       

       

            android:name=".VideoSubtitleList"

            android:label="@string/title_activity_video_subtitle_list" >

       

       

            android:name=".VideoViewBuffer"

            android:label="@string/title_activity_video_buffer" >

       

   

 

 

工程对应网址

/*
 * Copyright (C) 2013 YIXIA.COM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.vov.vitamio.demo;


import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;




import io.vov.vitamio.Vitamio;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * List
 */
public class VitamioListActivity extends ListActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Vitamio.isInitialized(getApplicationContext());


setListAdapter(new SimpleAdapter(this, getData(), android.R.layout.simple_list_item_1, new String[] { "title" }, new int[] { android.R.id.text1 }));
}


protected List> getData() {
List> myData = new ArrayList>();
addItem(myData, "MediaPlayer", new Intent(this, MediaPlayerDemo.class));
addItem(myData, "VideoView", new Intent(this, VideoViewDemo.class));
addItem(myData, "MediaMetadata", new Intent(this, MediaMetadataRetrieverDemo.class));
addItem(myData, "VideoSubtitle", new Intent(this, VideoSubtitleList.class));
addItem(myData, "VideoViewBuffer", new Intent(this, VideoViewBuffer.class));
return myData;
}


protected void addItem(List> data, String name, Intent intent) {
Map temp = new HashMap();
temp.put("title", name);
temp.put("intent", intent);
data.add(temp);
}


@SuppressWarnings("unchecked")
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Map map = (Map) l.getItemAtPosition(position);
Intent intent = (Intent) map.get("intent");
startActivity(intent);
}


}


推荐阅读
  • Android开发实现的计时器功能示例
    本文分享了Android开发实现的计时器功能示例,包括效果图、布局和按钮的使用。通过使用Chronometer控件,可以实现计时器功能。该示例适用于Android平台,供开发者参考。 ... [详细]
  • 本文介绍了使用kotlin实现动画效果的方法,包括上下移动、放大缩小、旋转等功能。通过代码示例演示了如何使用ObjectAnimator和AnimatorSet来实现动画效果,并提供了实现抖动效果的代码。同时还介绍了如何使用translationY和translationX来实现上下和左右移动的效果。最后还提供了一个anim_small.xml文件的代码示例,可以用来实现放大缩小的效果。 ... [详细]
  • 拥抱Android Design Support Library新变化(导航视图、悬浮ActionBar)
    转载请注明明桑AndroidAndroid5.0Loollipop作为Android最重要的版本之一,为我们带来了全新的界面风格和设计语言。看起来很受欢迎࿰ ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • Android系统移植与调试之如何修改Android设备状态条上音量加减键在横竖屏切换的时候的显示于隐藏
    本文介绍了如何修改Android设备状态条上音量加减键在横竖屏切换时的显示与隐藏。通过修改系统文件system_bar.xml实现了该功能,并分享了解决思路和经验。 ... [详细]
  • 本文介绍了Android 7的学习笔记总结,包括最新的移动架构视频、大厂安卓面试真题和项目实战源码讲义。同时还分享了开源的完整内容,并提醒读者在使用FileProvider适配时要注意不同模块的AndroidManfiest.xml中配置的xml文件名必须不同,否则会出现问题。 ... [详细]
  • 在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板
    本文介绍了在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板的方法和步骤,包括将ResourceDictionary添加到页面中以及在ResourceDictionary中实现模板的构建。通过本文的阅读,读者可以了解到在Xamarin XAML语言中构建控件模板的具体操作步骤和语法形式。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
  • 本文介绍了一款名为TimeSelector的Android日期时间选择器,采用了Material Design风格,可以在Android Studio中通过gradle添加依赖来使用,也可以在Eclipse中下载源码使用。文章详细介绍了TimeSelector的构造方法和参数说明,以及如何使用回调函数来处理选取时间后的操作。同时还提供了示例代码和可选的起始时间和结束时间设置。 ... [详细]
  • Android自定义控件绘图篇之Paint函数大汇总
    本文介绍了Android自定义控件绘图篇中的Paint函数大汇总,包括重置画笔、设置颜色、设置透明度、设置样式、设置宽度、设置抗锯齿等功能。通过学习这些函数,可以更好地掌握Paint的用法。 ... [详细]
  • 本文详细介绍了Android中的坐标系以及与View相关的方法。首先介绍了Android坐标系和视图坐标系的概念,并通过图示进行了解释。接着提到了View的大小可以超过手机屏幕,并且只有在手机屏幕内才能看到。最后,作者表示将在后续文章中继续探讨与View相关的内容。 ... [详细]
  • 今天就跟大家聊聊有关怎么在Android应用中实现一个换肤功能,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根 ... [详细]
  • android 触屏处理流程,android触摸事件处理流程 ? FOOKWOOD「建议收藏」
    android触屏处理流程,android触摸事件处理流程?FOOKWOOD「建议收藏」最近在工作中,经常需要处理触摸事件,但是有时候会出现一些奇怪的bug,比如有时候会检测不到A ... [详细]
author-avatar
钟爱胖胖
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有