zoukankan      html  css  js  c++  java
  • android 布局特点

    <LinearLayout
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:orientation="horizontal">
          <TextView
             android:id="@+id/item_title"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
             android:layout_marginLeft="10dp"
             android:layout_toLeftOf="@+id/iv_more"
             android:layout_toRightOf="@id/item_image"
             android:ellipsize="end"
             android:lines="1"
             android:singleLine="true"
             android:text="欢迎观看我的博客"
             android:textColor="@color/fontColor"
             android:textSize="14sp" />
           <TextView
             android:id="@+id/item_look"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
             android:layout_marginLeft="10dp"
             android:layout_toLeftOf="@+id/iv_more"
             android:layout_toRightOf="@id/item_image"
             android:ellipsize="end"
             android:lines="1"
             android:singleLine="true"
             android:text="试看"
             android:textColor="@color/mainColor"
             android:textSize="11sp"
             android:background="@drawable/shape_column_look"/>
    </LinearLayout>

     

    上面的布局就是上图框中的布局 ,这里我们想实现的是这样 

    但往往出现了这样

     我们希望的是试看不会被顶掉,但虽然看着简单其实,如果不知道使用布局技巧的话就只能自定义view了,但自定义View的计算还是非常麻烦

    解决方案:

    其实布局很简单就只要加一句

    android:layout_weight="1"
    如下
    <LinearLayout
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:orientation="horizontal">
          <TextView
             android:id="@+id/item_title"
             android:layout_width="wrap_content"
    android:layout_weight="1" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_toLeftOf="@+id/iv_more" android:layout_toRightOf="@id/item_image" android:ellipsize="end" android:lines="1" android:singleLine="true" android:text="欢迎观看我的博客" android:textColor="@color/fontColor" android:textSize="14sp" /> <TextView android:id="@+id/item_look" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_toLeftOf="@+id/iv_more" android:layout_toRightOf="@id/item_image" android:ellipsize="end" android:lines="1" android:singleLine="true" android:text="试看" android:textColor="@color/mainColor" android:textSize="11sp" android:background="@drawable/shape_column_look"/> </LinearLayout>
    就ok了是不是很简单啊~~快来学习吧~




  • 相关阅读:
    Jquery实现Gridview全选功能
    SQL Server日期计算
    避免表格table被撑开变形的CSS代码实例
    oracle游标使用
    最短路径算法及应用
    Jquery实现GridView隔行变色,鼠标经过变色,单击或者选中变色
    【项目】项目109
    【项目】项目107
    【项目】项目111
    【项目】项目110
  • 原文地址:https://www.cnblogs.com/woaixingxing/p/6834736.html
Copyright © 2011-2022 走看看