2014-10-25Android学习------布局处理(四)------ListView的item点击之后的布局

我学习Android都是结合源代码去学习,这样比较直观,非常清楚的看清效果,觉得很好,今天的学习源码是网上找的个HealthFood 源码 百度搜就知道很多下载的地方

本节学习接上篇布局学习(二) 地址:http://blog.youkuaiyun.com/u014737138/article/details/40480291

当我们把ListView布局好之后,我们就可以看到很多行,但是对行的点击操作,应该设置它跳转到另外一个activity中去,

这就是它的item的点击事件了,我们先想想应该需要哪些必要的控件:

1.返回按钮   最好要的,因为我们还需要返回去查看下一条item的

2.其他的比如文本显示,图片显示控件等等

那么我先看看效果图:



这一节我们需要学习的关于布局的知识点有以下这些:

1.子线性布局里面的返回按钮:

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android" 命名空间,这一行可以不写,写了如果报错就clean一把
        android:layout_width="fill_parent"宽度填充父窗体
        android:layout_height="wrap_content"高度包括内容
        android:background="@drawable/food_info_title_background"//整个子线性布局的图片
        android:orientation="horizontal" >水平方向


        <Button
            android:id="@+id/backbutton" 加上id,点击事件是返回上一个activity
            android:layout_width="wrap_content"包裹内容,也就是按钮背景图片的宽度
            android:layout_height="wrap_content"包裹内容,也就是按钮背景图片的高度
            android:layout_margin="10dp"//这行设置代表的意思是  Button控件与父窗体间隔10dp放置,也就是从左边起隔10dp  从效果图中很容易看清
            android:background="@drawable/btn_back" />//按钮背景图片
    </LinearLayout>


2.  相对布局:放置一个图片,图片的右边是一个

相对布局有个特点,就是有且仅有一行,就是在视图上只显示一行,不会多显示

  <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"//命名空间,可以不写
        android:layout_width="fill_parent"//相对布局的宽度是填充父窗体
        android:layout_height="wrap_content"//相对布局的高度是包裹内容,也就是从子控件里面,要显示的最大高度相匹配
        android:background="@color/white" >//背景颜色设置为白色,从资源索引文件里面找


        <Button  第一个放置一个牛奶
            android:id="@+id/Button"// 增加一个id方便动态设置内容
            android:layout_width="100dp"//显示的指定宽高,是个正方形,
            android:layout_height="100dp"
            android:layout_margin="10dp"//与父窗体的间隙
            android:background="@drawable/pork"背景颜色
            android:clickable="false" 不可以点击,没有点击事件
            android:padding="4dp"
            android:textColor="@color/black" />


        <TextView 按钮的右边放置一个文本控件
            android:id="@+id/TextView03" 增加一个id 动态设置值
            android:layout_width="350dp" 显示指定宽度
            android:layout_height="wrap_content"  高度为包裹内容
            android:layout_margin="10dp"
            android:layout_toRightOf="@id/Button"在按钮的右边
            android:background="@color/white"背景颜色为白色
            android:text="@string/text1"默认的内容
            android:width="10px" />文字大小
    </RelativeLayout>


3.中间放置一个TextView

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"//距离上面的相对布局的距离为15dp
        android:background="@drawable/food_info_middle_background"背景图片
        android:gravity="center_vertical"
        android:text="@string/middle"文字
        android:textColor="@color/white" />


4.用于显示不能搭配的食物列表

这里又再一次使用ListView控件,整个布局文件中有且仅有一个ListView构件,它的id是系统自定义的,

    <ListView
        android:id="@id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:focusable="false" >//每一行的item是不能被点击的
    </ListView>


总结:对布局文件再一次熟悉,做中学

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值