不多讲直接上代码

1.Activity 对应的布局文件如下:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:fadingEdge="vertical"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="10dp"
android:id="@+id/funtable"> </LinearLayout> </ScrollView>

2.Activity 实现类

package com.test.appdemo1.actlearn;

import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import com.test.appdemo1.R;
import com.test.appdemo1.R.string; /**
* 功能学习
* @package com.test.appdemo1.actlearn
* @author Administrator
* @date 2014-3-1 下午11:16:31
*/
public class FunPageActivity extends Activity { private LinearLayout funListView = null; private Builder dialog = null; protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.funtest);
funListView = (LinearLayout)findViewById(R.id.funtable);
dialog = new Builder(this);
initGridView();
} /**
*初使化UI
*/
private void initGridView() {
int ii = 1008601;int idx = 1;
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT,1f);
for(int i=1;i<=9;i++){
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.HORIZONTAL);
for(int j=1;j<=3;j++){
Button btn = new Button(this);
String key = "funPageBtn"+idx;idx++;
btn.setText(getString(getStringVal(key)));
Log.d("FUNCTION",key);
btn.setId(ii++);
btn.setOnClickListener(new BtnClick());
layout.addView(btn,param);
}
funListView.addView(layout);
} } /**
* 按纽单击处理
*/
class BtnClick implements OnClickListener{
public void onClick(View v) {
Button btn = (Button)v;
//简单显示会话框
showDialog(""+btn.getText(),btn.getText().toString()+"=="+btn.getId());
}
} /**
* 通过 R.string 类的属性名获取属性值
* @param str
* @return
*/
public int getStringVal(String str){
try{
Class<string> cls = R.string.class;
return cls.getDeclaredField(str).getInt(null);
}catch(Exception ex){
ex.printStackTrace();
}
return 0;
} /**
* 会话框
* @param title
* @param msg
*/
private void showDialog(String title,String msg){
dialog.setIcon(R.drawable.ic_launcher).setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
arg0.cancel();
}
}).setTitle(title).setMessage(msg).show();
}
}

3.资源文件部分如下:

 <string name="funPageBtn1">底部选项卡</string>
<string name="funPageBtn2">Fun 2</string>
<string name="funPageBtn3">Fun 3</string>
<string name="funPageBtn4">Dialog Test</string>
<string name="funPageBtn5">Fun 2</string>
<string name="funPageBtn6">Fun 3</string>
<string name="funPageBtn7">Dialog Test</string>
<string name="funPageBtn8">Fun 2</string>
<string name="funPageBtn9">Fun 3</string>
<string name="funPageBtn10">Dialog Test</string>
<string name="funPageBtn11">Fun 2</string>
<string name="funPageBtn12">Fun 3</string>
<string name="funPageBtn13">Dialog Test</string>
<string name="funPageBtn14">Fun 2</string>
<string name="funPageBtn15">Fun 3</string>
<string name="funPageBtn16">Dialog Test</string>
<string name="funPageBtn17">Fun 2</string>
<string name="funPageBtn18">Fun 3</string>
<string name="funPageBtn19">Dialog Test</string>
<string name="funPageBtn20">Fun 2</string>
<string name="funPageBtn21">Fun 3</string>
<string name="funPageBtn22">Dialog Test</string>
<string name="funPageBtn23">Fun 2</string>
<string name="funPageBtn24">Fun 3</string>
<string name="funPageBtn25">Dialog Test</string>
<string name="funPageBtn26">Fun 2</string>
<string name="funPageBtn27">Fun 3</string>

4.效果

共同学习进步!

在LinearLayout中实现列表,列表采用LinearLayout横向布局-android学习的更多相关文章

  1. 飞流直下的精彩 -- 淘宝UWP中瀑布流列表的实现

    在淘宝UWP中,搜索结果列表是用户了解宝贝的重要一环,其中的图片效果对吸引用户点击搜索结果,查看宝贝详情有比较大的影响.为此手机淘宝特意在搜索结果列表上采用了2种表现方式:一种就是普通的列表模式,而另 ...

  2. 如何:在 SharePoint 中创建外部列表

    在创建外部内容类型后创建外部列表是一项非常简单的任务,有如下4种方式进行: 可使用 Microsoft SharePoint Designer 2010 浏览器来完成 VS2010的列表实例 采用代码 ...

  3. 集合映射中的映射列表(使用xml文件)

    如果持久化类具有List对象,我们可以通过映射文件中的类的<list>元素或注释来映射List. 在这里,我们正在使用论坛的场景,其中一个问题有多个答案. 在这里,我们使用论坛的场景,其中 ...

  4. Andriod中textview垂直水平居中及LinearLayout内组件的垂直布局

    1.textview 垂直水平居中的设置 Android:gravity="center_vertical|center" 2.LinearLayout中设置控件垂直布局,默认的是 ...

  5. 从下拉菜单拖拽一个元素 出来,插入到页面中的app 列表中

    1,实现功能:从下拉菜单拖拽一个元素 出来,插入到页面中的app 列表中 并实现app向后移动一个元素的位置: 2.实现思路: 01.遍历下拉菜单,添加拖拽方法,实现位置移动功能: 02.遍历app列 ...

  6. 【循序渐进学Python】2. Python中的序列——列表和元组

    序列概览 在Python中有六种内建的序列:列表.元组.字符串.Unicode字符串.buffer对象和xrange对象.在这里暂时只讨论列表和元组.列表和元组的主要区别在于:列表可以修改,元组(不可 ...

  7. C# 中获取时区列表

    c#中获取时区列表 下面方法获得的仅仅用来显示和使用,无法用来进行时间转换. public static List<DisplayTimeZone> GetSystemTimeZones( ...

  8. java中把list列表转为arrayList以及arraylist数组截取的简单方法

    java中把list列表转为arrayList以及arraylist数组截取的简单方法 package xiaobai; import java.util.ArrayList; import java ...

  9. delphi中获得进程列表或想要的进程(枚举进程、遍历进程)

    一个常见的编程任务是枚举所有运行的"应用程序".Windows 任务管理器就是一个很好的例子.它用两种方式列出"应用程序".任务管理器的第一个选项卡列出桌面上的 ...

随机推荐

  1. 为什么要在<button>元素中添加type属性

    在HTML中<button> 标签定义一个按钮. <button type="button">Click Me!</button> 在 butt ...

  2. FormBorderStyle.None 时候最大化不遮盖任务栏

    this.FormBorderStyle = FormBorderStyle.None;             this.MaximumSize = new Size(Screen.PrimaryS ...

  3. Visual Studio 中TODO List的使用

    http://msdn.microsoft.com/en-us/library/txtwdysk.aspx 工欲善其事,必先利其器 When the Task List is open, you ca ...

  4. 团体程序设计天梯赛-练习集L1-003. 个位数统计

    L1-003. 个位数统计 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个k位整数N = dk-1*10k-1 + . ...

  5. orale--varchar2(5) vs varchar2(5 byte) vs varchar2(5 char)

    varchar2(5) == varchar2(5 byte)------> 'abcde' 但是中文不是5 个字符 varchar2(5 char)----> 'abcde'

  6. 常用的富文本框插件FreeTextBox、CuteEditor、CKEditor、FCKEditor、TinyMCE、KindEditor ;和CKEditor实例

    http://www.cnblogs.com/cxd4321/archive/2013/01/30/2883078.html 目前市面上用的比较多的富文本编辑器有: FreeTextBox 一个有很多 ...

  7. IOS - IOS之同步请求、异步请求、GET请求、POST请求

    1.同步请求可以从因特网请求数据,一旦发送同步请求,程序将停止用户交互,直至服务器返回数据完成,才可以进行下一步操作, 2.异步请求不会阻塞主线程,而会建立一个新的线程来操作,用户发出异步请求后,依然 ...

  8. if语句写在while语句外面效率更高

    为了排除某些特殊的文件后缀名,一开始我自然而然的这样写,判断每一个文件的后缀名: // 去除后缀名 foreach (const QString &strKey, local_map.keys ...

  9. 使用PHP抓取网站ico图标

    网站许久没用更新,以后会经常更新,本次分享一个使用PHP抓取网站ico的程序,提供一个网站列表后对网站的ico进行下载抓取,具体代码如下: <?php /** * 更新热站ico * gao 2 ...

  10. Unicode汉字编码表

    U+  0   1  2  3  4   5  6   7   8   9   A  B  C  D  E  F  ------------------------------------------ ...