Android学习之路(2)--奖牌列表(布局嵌套)--2017_01_10

来源:互联网 发布:linux查看被占用的内存 编辑:程序博客网 时间:2024/04/28 10:00

昨天发表了一篇简单的计算器实例的博客,计算器是在一个LinearLayout中完成的各项功能,今天这篇博客的内容是使用布局嵌套,本实例主要是将线性布局与表格布局混合起来显示,即总的布局为垂直方向向上的布局,上面那个布局内部又是垂直方向的布局,下面那个布局也是线性布局,不过里面有一个表格,总共四个布局。

mian.xml的布局图片就不发了,大家直接看xml代码

main.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_main"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#aabbcc"    android:orientation="vertical"    tools:context="com.example.tigermini.themedallist.MainActivity">    <LinearLayout        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:orientation="vertical"        android:layout_weight="1">        <TextView            android:id="@+id/London"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:text="伦敦奥运"            android:textSize="5pt"            android:background="#00ff00"            android:layout_gravity="center_horizontal"            android:padding="10pt"            android:layout_weight="1"/>        <TextView            android:id="@+id/China"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:text="中国加油"            android:textSize="8pt"            android:background="#ff00ff"            android:layout_weight="3"/>    </LinearLayout>    <LinearLayout        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_weight="3">        <TableLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:stretchColumns="0,1,2,3">            <TableRow>                <TextView                    android:text="国家"                    android:background="#848484"                    android:padding="2dp"/>                <TextView                    android:text="金牌"                    android:background="#ff0000"                    android:padding="2dp"/>                <TextView                    android:text="银牌"                    android:background="#0000ff"                    android:padding="2dp"/>                <TextView                    android:text="铜牌"                    android:background="#00ff00"                    android:padding="2dp"/>            </TableRow>            <TableRow>                <TextView                    android:text="中国"                    android:background="#848484"                    android:padding="2dp"/>                <TextView                    android:text="*"                    android:background="#ff0000"                    android:padding="2dp"/>                <TextView                    android:text="**"                    android:background="#0000ff"                    android:padding="2dp"/>                <TextView                    android:text="***"                    android:background="#00ff00"                    android:padding="2dp"/>            </TableRow>            <TableRow>                <TextView                    android:text="美国"                    android:background="#848484"                    android:padding="2dp"/>                <TextView                    android:text="*"                    android:background="#ff0000"                    android:padding="2dp"/>                <TextView                    android:text="**"                    android:background="#0000ff"                    android:padding="2dp"/>                <TextView                    android:text="***"                    android:background="#00ff00"                    android:padding="2dp"/>            </TableRow>        </TableLayout>    </LinearLayout></LinearLayout>

下面是MainActivity.java的代码,没有一点改动,所有内容都在main.xml布局里面。

MainActivity.javapackage com.example.tigermini.themedallist;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);    }}

附上CSDN源代码的网址
http://download.csdn.net/detail/wjy1025104554/9733491

0 0
原创粉丝点击