安卓常用的三行布局

第一次写博客,记录自己在日常开发中用到的实用的技术和技巧,与各位共享;

最近在app开发当中涉及到资讯方面的布局,举个例子?


在上面这个新闻详情界面,布局就是标准的三行布局: 上面一个titlebar,中间是content,下面是交互;

类似这样的布局,快速而高效的就是利用RelativeLayout:

最上方是一个自定义的titlebar,当然换成你喜欢xxbar都可以

<include layout="@layout/title_bar"/>
中面是个scrollview,其中需要below我们的titlebar,还需要above我们下边的交互栏

<ScrollView
    android:layout_above="@+id/ll_introduce"
    android:layout_below="@+id/title_bar"
    android:id="@+id/news_scrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
最后是我们的交互布局,只需要alignParentBottom,因为我们的scrollview滑动的同时也需要沉底

<LinearLayout
    android:id="@+id/ll_introduce"
    android:focusableInTouchMode="true"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
大功告成,是不是很简单,这样做的好处是高度自适应,并且不会覆盖我们的底部布局,over;





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用LinearLayout和weight属性来实现这个布局,具体方法如下: 1.在布局文件中使用LinearLayout作为父容器,设置orientation属性为vertical,表示垂直方向排列。 2.在LinearLayout中嵌套三个子LinearLayout,分别表示三,每中包含对应数量的TextView。 3.为每个TextView设置layout_weight属性,表示在LinearLayout中的相对权重。例如,第一只有一个TextView,其layout_weight设置为1,第二有两个TextView,每个TextView的layout_weight设置为1,第三有三个TextView,每个TextView的layout_weight设置为1。 下面是一个示例布局代码: ```xml <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!-- 第一 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="TextView 1" /> </LinearLayout> <!-- 第二 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="TextView 2" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="TextView 3" /> </LinearLayout> <!-- 第三 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="TextView 4" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="TextView 5" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="TextView 6" /> </LinearLayout> </LinearLayout> ``` 在这个示例布局中,我们使用了三个LinearLayout,分别表示三。在每个LinearLayout中,我们设置了对应数量的TextView,并为每个TextView设置了layout_weight属性,表示在LinearLayout中的相对权重。这样每中的TextView会根据其layout_weight属性的值进分配空间,从而实现每显示不同数量的TextView。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值