热门标签 | HotTags
当前位置:  开发笔记 > 前端 > 正文

线性布局下最左/右问题

在Android中,只有垂直的linearlayout属性里面的内部组件靠左靠右才有效,同理,水平的linearlayout属性里面的内部组件靠上靠下才有效,否则无效。由此考虑如何让水平l

在Android中,只有垂直的linearlayout属性里面的内部组件靠左靠右才有效,同理,水平的linearlayout属性里面的内部组件靠上靠下才有效,否则无效。

由此考虑如何让水平linearlayout中同一行内组件靠左靠右显示呢?


法一:这个如果用RelativeLayout控制就很容易,要是用LinearLayout也不是不可能。思路就是在中间放置一个控件,让其透明,并设置weight为1.0。

   android:layout_ 

   android:layout_ 

   android:orientation="horizontal"> 

   

       android:layout_ 

       android:layout_ 

       android:text="@string/hello_world" /> 

   

       android:alpha="0" 

       android:layout_ 

       android:layout_ 

       android:layout_weight="1.0" /> 

   

       android:layout_ 

       android:layout_ 

       android:text="@string/hello_world" /> 

  



法二:线性布局嵌套。

 <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:background="#acc">
        <LinearLayout 
        android:orientation="vertical" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_weight="1">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left|center_vertical"
            android:layout_marginLeft="3.0dip"
            android:background="@drawable/move_on1"/>
            
        <LinearLayout 
        android:orientation="vertical" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_weight="1">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|center_vertical"
            android:layout_marginRight="3.0dip"
            android:background="@drawable/stopa" />
            
    




推荐阅读
author-avatar
小新亚笔
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有