安卓小日记练习(2)从listview到主界面整体布局


         我们在上一篇文章中,已经实现了一个基本的listview,我们接下来考虑的是实现listview所在的主界面的其他空间。然后再来实现listview更多的功能,比如动态加载item和设置点击事件等等。正如上一篇文章实现listview的时候,item里先只实现了一个textview,实现了设置后才改成三个的。其实这也可以看出安卓很大程度上就是分解问题解决问题。所以在确定好整体的设计思路之后,一个个的分解问题,一格格的解决,实现。用对javascript的原则来说就是渐进增强,支持平稳退化。所以我们现在实现主界面底下那一排的控件。

        思路:

      我们要实现的最后一排有多个控件,而上面是一个listview,我们的listview的高度已经定下来了,为下面一排的控件留出了空间。我们考虑把最后一排多个空间用一个linearlayout包裹起来,也就是上下两个layout,我们最外层的layout设置属性值为vertical。所以说第一步的思路应该是layout封装多个控件。而且,用layout 的嵌套的层级关系来完成整个界面设计的框架(水平和垂直),接下来面临的问题是,怎么调整各个空间之间的位置,我们将会用到weght属性,它将相对的重新分配宽度比例,这时候,我们又遇到新的问题,就是仅仅这么分配,它们之间的距离也无法调整,这时候,我们使用一种控件:view来参与weight权重的分配,这个控件是透明的。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    
    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent" 
        android:layout_height="380dp" >
        </ListView>

    	 <LinearLayout
            android:id="@+id/bottom"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
            
    	     
    	     <View
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="0dp"
                />
    	     
            <ImageView 
                android:id="@+id/image_view1"
                android:layout_height="15dip"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/blacklong"
                android:clickable = "true"
                 />
            <View
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="0dp"
                />
            
            <ImageView
                android:id="@+id/imge_view2"
                android:layout_height="15dip"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/aug"
                android:clickable = "true"
                />
            <View
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="0dp"
                />
            
            <ImageView
                android:id="@+id/imge_view3"
                android:layout_height="15dip"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/divi"
                android:clickable = "true"
                />
            <View
                android:layout_width="0dp"
                android:layout_weight="2"
                android:layout_height="0dp"
                />
            
                <ImageView
                android:id="@+id/imge_view4"
                android:layout_height="15dip"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/year"
                android:clickable = "true"
                />
            <View
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="0dp"
                />
            
                <ImageView
                android:id="@+id/imge_view5"
                android:layout_height="15dip"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/divi"
                android:clickable = "true"
                />
            <View
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="0dp"
                />
            
             <ImageView
                android:id="@+id/imge_view6"
                android:layout_height="15dip"
                android:layout_width="wrap_content"
                android:layout_weight="2"
                android:src="@drawable/add"
                android:clickable = "true"
                />
            <View
                android:layout_width="0dp"
                android:layout_weight="2"
                android:layout_height="0dp"
                />
             <ImageView
                android:id="@+id/imge_view7"
                android:layout_height="15dip"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/divi"
                android:clickable = "true"
                />
             <View
                android:layout_width="0dp"
                android:layout_weight="2"
                android:layout_height="0dp"
                />
            
            <ImageView
                android:id="@+id/image_view8"
                android:layout_marginTop="5dip"
                android:layout_height="wrap_content"
                android:layout_weight="4"
				android:layout_width="wrap_content"
                android:src="@drawable/blacklong2"
                android:clickable = "true"
                 />
            <View
                android:layout_width="0dp"
                android:layout_weight="8"
                android:layout_height="0dp"
                />
            
            </LinearLayout>
    
</LinearLayout>
小结:

1.layout 包装控件,并layout之间嵌套(水平和垂直)可以构成界面的初级的体系结构。

2.weight可以按照相对位置重新分配控件宽度

3.view可以参与到权重分配,从而调整位置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值