我们知道,在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]控件ImageView的常用属性
  2. android控件注意点(一)
  3. Android实现书籍翻页效果--扩展版(转)
  4. android设置系统语言,字体大小,字体样式导致widget控件失效
  5. Android API指南(二)自定义控件04之 位置说明

随机推荐

  1. Android快速开关机
  2. 三.如何创建窗口模式的Activity
  3. Android自定义Dialog二次调用报错解决方
  4. Android中事件分发机制详解
  5. 今天遇到Android2.3.3能运行的程序到andr
  6. Android中解决FragmentPagerAdapter刷新F
  7. Delphi APP 開發入門(二)Android/iOS設定,He
  8. QQ android 登录模块简单分析
  9. Android(安卓)ListView刷新 (Handler/Ser
  10. Android-NDK开发之基础--Android(安卓)JN