(转)LinearLayout中实现水平方向上的两个Textview一个居左,一个居右的效果
2017-03-05 13:45
801 查看
原地址:http://blog.csdn.net/lb1207087645/article/details/49819453
我们知道,在LineraLayout中,当设置android:orientation="horizental" ,子控件的android:layout_gravity="left",android:layout_gravity="right"是无效的,所以我们可以改用比重的方法来达到两个textview一个居左,一个居右的效果,如下这种效果
设置 android:layout_width="0dp",android:layout_height="wrap_content",android:layout_weight="1"这三个属性后,就会把match_parent剩下的布局给撑满,所以会把右边那个textView挤到最右端。
这样就能达到在LinLinearLayout中水平方向上的有两个textview一个居左,一个居右的效果。
我们知道,在LineraLayout中,当设置android:orientation="horizental" ,子控件的android:layout_gravity="left",android:layout_gravity="right"是无效的,所以我们可以改用比重的方法来达到两个textview一个居左,一个居右的效果,如下这种效果
<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一个居左,一个居右的效果。
相关文章推荐
- LinearLayout中实现水平方向上的两个textview一个居左,一个居右的效果
- TabLayout 和ViewPager和Fragment的多页面滑动(主要实现一个水平的布局用来展示Tabs加上ViewPager实现联动效果)
- Android-LinearGradient实现TextView字体渐变的效果
- CheckableLinearLayout 实现一个可选中的layout 以及 CheckableImageView
- Android LinearLayout+ScrollView 模仿ListView效果,是为了使每个Item的EditText无法失去焦点
- 在同一个layout里,多个textview单行滚动显示(跑马灯效果)
- <TextView>实现一个有趣的小效果
- 文本内容超过TextView的长度时,实现文本内容水平滚动效果
- Andriod LinearLayout内组件textview垂直水平居中
- 51.使用HorizontalScrollView+LinearLayout实现文字+图片的自动跑马灯效果
- android动态布局:用java代码实现LinearLayout以及TextView
- 使用LinearLayout+TextView实现底部导航栏,重复切换页面不会重新加载
- 如何实现以上垂直方向上两个TextView内文字左右对齐
- Andriod中textview垂直水平居中及LinearLayout内组件的垂直布局
- Android底部导航栏实现(三)之TextView+LinearLayout
- android 给LinearLayout中添加一定数量的控件,并让着一定数量的控件从右到左移动,每隔若干秒停顿一下,最后一个view链接第一个view,然后继续移动循环往复,形成一个死循环简单动画效果
- 一个textview实现文字在图片上面的效果
- TextView 实现走马观灯 水平滚动效果
- 简易实现 TextView单行文本水平触摸滑动效果
- android用Adapter实现ListView的初始化报错android.widget.LinearLayout cannot be cast to android.widget.TextView