Android 仿携程活动列表边框布局

实现如下图所示的一个页面布局

布局框架

 

思路讲解:

 1.一开始的思路是使用android提供的画布将布局中的内容花下来,之后想了想觉得比较麻烦,所以又开启了另外一条思路。

 2.如上图“布局框架”所示。最外部是一个大布局(RelativeLayout),里面包含了两个控件(一个标题,和一个LinearLayout(包含了内容)的控件)。布局做好之后,下面就是计算高度的问题了。假设标题高度为40dp,则内容外层的布局只需要向上填充19像素,标题的高度的一半就能够和内容外层布局的边框居中对齐。然后再给标题的加上drawableleft和drawableright。问题就搞定了。

 

实现代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:background="#f4f4f4"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff" >

        

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="120dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="19dp"
            android:gravity="center"
            android:background="@drawable/trip_bg_et_order_remind" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:text="三等奖发牢骚的减肥了涉及到法律就是的浪费就撒了点附近拉克丝的减肥了快速的减肥卢卡斯剪短发了空间撒都浪费就死啦的风景老师啥地方撒旦路附近拉萨的减肥了三等奖" />
        </LinearLayout>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:layout_centerHorizontal="true"
            android:background="#ffffff"
            android:gravity="center"
            android:drawableRight="@drawable/trip_icon_teset"
            android:drawableLeft="@drawable/trip_icon_teset"
            android:text="    杭州会爱上他?    " />
    </RelativeLayout>

</LinearLayout>

备注:上面这个小demo还有很多不足之处,有兴趣的同学可以给其补上,这里仅提供一个思路。

 

posted on 2015-01-14 14:59  飘杨......  阅读(964)  评论(0编辑  收藏  举报