`
airshiplay
  • 浏览: 43404 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

LinearLayout中的控件两端对齐

阅读更多

在android中的控件LinearLayout 中的android:gravity="center"  属性,要么是居左、居右、居中对齐,不能达到双控件 两端对齐,

要实现两端对齐方式,要采用 中间增加一个控件的方式实现 ,并设置属性weight=1。

 

具体的布局文件如下:

<?xml version="1.0″ encoding="utf-8″?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/Button01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button01" >
    </Button>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <Button
        android:id="@+id/Button02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button02" >
    </Button>

</LinearLayout>

 效果如图:

   
       

实现两个button按钮 两端对齐
 

 

 

 

  • 大小: 31.3 KB
分享到:
评论
2 楼 atwind 2015-05-24  

这算不算投机取巧?
1 楼 ufo22940268 2014-06-04  
我解决了

https://github.com/ufo22940268/android-justifiedtextview

相关推荐

Global site tag (gtag.js) - Google Analytics