常用布局

左中右布局

左中右布局
    <!-- 左中右布局(ToolBar),左右内容可设置 padding。缺点:单行。 -->

    <!-- 1、父布局,使用 RelativeLayout -->
    <!-- 2、左内容,默认居左 -->
    <!-- 3、中间内容,使用 android:layout_centerInParent="true" 居中 -->
    <!-- 4、右内容,使用 android:layout_alignParentRight="true" 居右 -->
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="40.0dp"
        android:background="#ff6600"
        android:gravity="top">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="详细资讯"
            android:textColor="#ffffffff"
            android:textSize="20.0sp"/>

        <ImageButton
            android:layout_width="50.0dp"
            android:layout_height="fill_parent"
            android:background="@null"
            android:contentDescription=""
            android:gravity="center"
            android:scaleType="centerInside"
            android:src="@drawable/ic_core_arrow_l"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_alignParentRight="true"
            android:background="@null"
            android:gravity="center"
            android:text="收藏"
            android:textColor="#ffffffff"
            android:textSize="14.0sp"/>
    </RelativeLayout>

左右布局

左右布局
    <!-- 左右布局(更多 item ),优点:左右可随意设置图标等额外内容。 -->
    <!-- 1、父布局,使用 LinearLayout -->
    <!-- 2、左内容,使用 android:layout_width="0.0dp" 占满屏幕(左可以设置图标等额外内容)。 -->
    <!-- 3、右内容,占据左满屏后的空间 -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <TextView
            android:layout_width="3.0dp"
            android:layout_height="16sp"
            android:layout_marginLeft="5.0dp"
            android:layout_marginRight="5.0dp"
            android:background="#ff6501"
            android:gravity="start|center_vertical"
            android:text=""/>

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="0.0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1.0"
            android:gravity="left"
            android:text="最新资讯"
            android:textColor="#282828"
            android:textSize="16.0sp"
            android:textStyle="bold"/>

        <TextView
            android:id="@+id/tv_more"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#ffffff"
            android:text="更多"
            android:textColor="#969696"
            android:textSize="13.0sp"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_core_arrow_small"
            android:contentDescription="@null"/>
    </LinearLayout>

左右布局

左右布局
    <!-- 左右布局(更多 item ),缺点:右内容过长会覆盖左内容上。 -->
    <!-- 1、父布局,使用 RelativeLayout -->
    <!-- 2、左内容,默认左。 -->
    <!-- 3、右内容,使用 android:layout_alignParentRight="true" 居右。 -->
    <!-- 4、备注:左右内容可以使用 android:layout_toRightOf="@id/tv_more" 设置额外图标等内容 -->


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

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:text="最新资讯"
            android:textColor="#282828"
            android:textSize="16.0sp"
            android:textStyle="bold"/>


        <TextView
            android:id="@+id/tv_more"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerInParent="true"
            android:text="更多"
            android:textColor="#969696"
            android:textSize="13.0sp"/>

    </RelativeLayout>

左右平分+间隔线

左右平分+间隔线
    <!-- 上间隔线 -->
    <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="1.0px"
                android:background="#ddd"
                android:orientation="horizontal">
    </LinearLayout>

    <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

    <!-- 左右平分 -->
    <LinearLayout
                    android:id="@+id/ll_cancel"
                    android:layout_width="0.0dp"
                    android:layout_height="40.0dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:layout_toRightOf="@+id/iv_icon"
                        android:text="稍後再說"
                        android:textColor="#999999"
                        android:textSize="14.0sp"/>
    </LinearLayout>

    <!-- 左右间隔线 -->
    <LinearLayout
                    android:layout_width="1.0px"
                    android:layout_height="fill_parent"
                    android:background="#ddd">
    </LinearLayout>

    <LinearLayout
                    android:id="@+id/ll_open"
                    android:layout_width="0.0dp"
                    android:layout_height="40.0dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:layout_toRightOf="@+id/iv_icon"
                        android:text="去開啟"
                        android:textColor="#fe6200"
                        android:textSize="14.0sp"/>
                </LinearLayout>
    </LinearLayout>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,242评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,769评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,484评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,133评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,007评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,080评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,496评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,190评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,464评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,549评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,330评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,205评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,567评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,889评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,160评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,475评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,650评论 2 335

推荐阅读更多精彩内容

  • 1 UI布局 1.1日志的使用 【 verbose:详细信息(黑色) debug:调试信息(蓝色) info:...
    征程_Journey阅读 708评论 0 0
  • 写在前面 一直想写一写布局,趁今天有空好好总结一下,留着以后看。 综述 Android的布局有好多好多种,官方的、...
    林里icer阅读 31,875评论 1 25
  • ASDK布局使用Flexbox方式布局。 Flexbox 验证:http://nguyenhuy.github.i...
    黄x黄阅读 1,115评论 0 2
  • 1、水平居中 方法一:margin:0 auto; 是最常见的水平居中解决方案,但有其局限性:块级元素,已知宽度,...
    qsister阅读 1,100评论 0 1
  • flex布局是什么 Flex是Flexible Box的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性。F...
    耳_总阅读 633评论 0 1