我们知道,在LineraLayout中,当设置android:orientation="horizental" ,子控件的android:layout_gravity="left",android:layout_gravity="right"是无效的,所以我们可以改用比重的方法来达到两个textview一个居左,一个居右的效果,如下这种效果


Demo 如下

<LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    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        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="李四"/>LinearLayout>
设置 android:layout_width="0dp",android:layout_height="wrap_content",android:layout_weight="1"这三个属性后,就会把match_parent剩下的布局给撑满,所以会把右边那个textView挤到最右端。
这样就能达到在LinLinearLayout中水平方向上的有两个textview一个居左,一个居右的效果。

更多相关文章

  1. Android顶部工具栏和底部工具栏的简单实现代码
  2. 最全的PHP开发Android应用程序
  3. Android(安卓)圆角图片,基于Glide4.9 的 BitmapTransformation,可
  4. Android实现书籍翻页效果--扩展版
  5. Android(安卓)UI开发第九篇——SlidingDrawer 抽屉效果
  6. Android实现书籍翻页效果--扩展版(转)
  7. android android屏幕禁止休眠和锁屏的方法
  8. android 过渡动画研究
  9. Android实时监控项目第一篇:项目分析及AVD模拟效果图

随机推荐

  1. 漫画设计模式:什么是 “职责链模式” ?
  2. 配置vscode的cmder的方法
  3. 前端杂记-环境搭建
  4. mysql 存在更新 不存在插入
  5. mysql创建存储过程失败1307错误解决
  6. 0506作业
  7. h5红包活动特辑,红包H5营销活动如何制作
  8. 随时随地创建在线考试,“无纸化”考试时代
  9. 游戏Python开发从青铜到王者,你必须了解哪
  10. Unity3D实现模型体积拖拽变化