【Android开发】范例1-使用表格布局与线性布局实现分类工具栏

实现一个横屏的带有各种功能分类的主界面,效果如图:


素材:


实现代码:

MainActivity:

package com.example.test;


import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.FrameLayout;


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

res/layout/main.xml:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/tableLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:padding="10px"
    android:screenOrientation="landscape" >


    <!-- 表格TableRow行的android:layout_weight属性均设为1,
                  表示这三行平均分配整个视图空间-->
                  
    <!-- 第一行 -->


    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#FFFFEE00" >
        
        <LinearLayout android:id="@+id/linearlayout1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:layout_margin="10px"
            android:background="#FFFFFF">
            <TextView android:id="@+id/textView1"
                android:text="@string/time"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:gravity="center"
                style="@style/text"/>
        </LinearLayout>
        
        <LinearLayout android:id="@+id/linearlayout2"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:layout_margin="10px"
            android:background="#FFFFFF">
            <ImageView android:id="@+id/imageView1"
                android:src="@drawable/img01"
                android:layout_weight="1"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"/>
            <ImageView android:id="@+id/imageView2"
                android:src="@drawable/img02"
                android:layout_weight="1"
                android:layout_marginLeft="50px"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"/>
            <ImageView android:id="@+id/imageView3"
                android:src="@drawable/img03"
                android:layout_weight="1"
                android:layout_marginLeft="50px"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"/>
        </LinearLayout>
       
    </TableRow>
    
    
    <!-- 第二行 -->
    <TableRow android:id="@+id/tableRow2"
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:background="#FFFF6600">
        
        <LinearLayout android:id="@+id/linearlayout3"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:layout_margin="10px"
            android:background="#FFFFFF">
            <ImageView android:id="@+id/imageView4"
                android:src="@drawable/img04"
                android:layout_weight="1"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"/>
            <ImageView android:id="@+id/imageView5"
                android:src="@drawable/img05"
                android:layout_weight="1"
                android:layout_marginLeft="40px"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"/>
            <ImageView android:id="@+id/imageView6"
                android:src="@drawable/img06"
                android:layout_weight="1"
                android:layout_marginLeft="40px"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"/>
        </LinearLayout>
        
         <LinearLayout android:id="@+id/linearlayout4"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:layout_margin="10px"
            android:background="#FFFFFF">
            <ImageView android:id="@+id/imageView7"
                android:src="@drawable/img07"
                android:layout_weight="1"
                android:layout_margin="40px"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"/>
             <TextView android:id="@+id/textView2"
                android:text="刷取二维码"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:gravity="center_vertical"
                android:layout_weight="3"
                style="@style/text"/>
        </LinearLayout>
        
    </TableRow>
    
    
    <!-- 第三行 -->
    <TableRow android:id="@+id/tableRow3"
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:background="#CCCCCC">
         
         <LinearLayout android:id="@+id/linearlayout5"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:layout_margin="10px"
            android:background="#FFFFFF">
            <ImageView android:id="@+id/imageView8"
                android:src="@drawable/img08"
                android:layout_marginLeft="20px"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"/>
             <TextView android:id="@+id/textView3"
                android:text="电子邮件"
                android:layout_marginLeft="20px"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:gravity="center_vertical"
                style="@style/text"/>
        </LinearLayout>
        
    </TableRow>
</TableLayout>

res/values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>


    <string name="app_name">test3.1</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
    <string name="time">2015年3月29日17:27:00</string>


</resources>

res/values/styles.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    
     <style name="text">
       <item name="android:textSize">24px</item>
       <item name="android:textColor">#111111</item>
    </style>
	 
    <style name="AppBaseTheme" parent="android:Theme.Light"> 
    </style>


    <style name="AppTheme" parent="AppBaseTheme">
    </style>
</resources>
转载请注明出处:http://blog.csdn.net/acmman/article/details/44754519

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Android SDK开发范例大全是为了帮助开发人员更好地学习和使用Android SDK所提供的示例代码集合。 首先,Android SDK开发范例大全涵盖了各种不同的开发领域,包括UI设计、数据存储、网络通信、多媒体处理等等。每个范例都提供了详细的代码和说明文档,帮助开发人员理解并运用相应的功能。 例如,在UI设计方面,开发人员可以通过范例学习如何使用Android SDK提供的各种布局和控件来创建用户界面,以及如何处理用户输入和事件响应。 在数据存储方面,开发人员可以学习如何使用SQLite数据库来创建和管理数据表,以及如何进行数据的增删改查操作。 在网络通信方面,开发人员可以学习如何使用HTTP协议进行数据的传输,如何进行异步网络请求以及如何解析服务器返回的数据。 在多媒体处理方面,开发人员可以学习如何使用Android SDK提供的API进行图像处理、音频播放、视频播放等操作。 通过Android SDK开发范例大全,开发人员可以迅速上手Android开发并提高开发效率。范例的代码经过精心设计和优化,可以作为开发过程的参考和借鉴。同时,范例的说明文档也提供了详细的解释和用法,方便开发人员理解和运用。 总之,Android SDK开发范例大全是一个非常实用的资源,对于想要学习和精通Android开发开发人员来说,是一个宝贵的学习资料和工具。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

光仔December

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值