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了是不是很简单啊~~快来学习吧~




  • 相关阅读:
    MySQL 中无法 insert 文件路径 中的 backward slash的解决方法
    生成颜色代码的 Java程序
    公积金贷款不受影响 组合贷款有特殊
    ADOMD.NET Client Object架构
    心情•笔记20061231
    微软所谓的"无人工介入的自动的机器翻译系统"
    游戏中的微软
    商业智能的个人理解
    无日
    从电影死亡笔记看商业智能在治安领域的应用
  • 原文地址:https://www.cnblogs.com/woaixingxing/p/6834736.html
Copyright © 2011-2022 走看看