为了账号安全,请及时绑定邮箱和手机立即绑定

安卓简单布局样例_采用LinearLayout实现多列多行展示

标签:
Android

实现效果:

webp

代码:

  1. 布局文件:

<?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:background="#F3F3F3"
              android:orientation="vertical">
    <LinearLayout
            android:id="@+id/ll_top_split"
            android:layout_width="match_parent"
            android:layout_height="17dp"
            android:layout_marginTop="10dp"
            android:background="#FFFFFF"
            android:orientation="horizontal"/>

    <LinearLayout style="@style/row_style">

        <LinearLayout
                android:id="@+id/ll_test1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.33"
                android:orientation="vertical">

            <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@mipmap/ic_launcher"/>

            <TextView
                    style="@style/item_text_style"
                    android:text="测试1"/>
        </LinearLayout>

        <LinearLayout
                android:id="@+id/ll_test2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.33"
                android:orientation="vertical">

            <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@mipmap/ic_launcher"/>

            <TextView
                    style="@style/item_text_style"
                    android:text="测试2"/>
        </LinearLayout>

        <LinearLayout
                android:id="@+id/ll_test3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.33"
                android:orientation="vertical">

            <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@mipmap/ic_launcher"/>

            <TextView
                    style="@style/item_text_style"
                    android:text="测试3"/>
        </LinearLayout>

    </LinearLayout>
    <LinearLayout style="@style/row_style">

        <LinearLayout
                android:id="@+id/ll_test4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.33"
                android:orientation="vertical">

            <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@mipmap/ic_launcher"/>

            <TextView
                    style="@style/item_text_style"
                    android:text="测试4"/>
        </LinearLayout>

        <LinearLayout
                android:id="@+id/ll_test5"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.33"
                android:orientation="vertical">

            <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@mipmap/ic_launcher"/>

            <TextView
                    style="@style/item_text_style"
                    android:text="测试5"/>
        </LinearLayout>

        <!-- 下面是一个空的布局,用于占位,便于控件各占三分之一屏幕-->
        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.33"
                android:orientation="vertical"/>

    </LinearLayout>

    <LinearLayout
            android:id="@+id/ll_bottom_split"
            android:layout_width="match_parent"
            android:layout_height="15dp"
            android:background="#FFFFFF"
            android:orientation="horizontal"/></LinearLayout>
  1. styles.xml

<style name="item_text_style">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_gravity">center</item>
        <item name="android:layout_marginTop">11dp</item>
        <item name="android:background">#FFFFFF</item>
        <item name="android:gravity">center</item>
        <item name="android:textSize">13sp</item>
        <item name="android:textColor">#333333</item>
    </style>

    <style name="row_style">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:background">#FFFFFF</item>
        <item name="android:paddingTop">11dp</item>
        <item name="android:paddingBottom">11dp</item>
    </style>



作者:程序园中猿
链接:https://www.jianshu.com/p/2d39c4b5832d


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消