我是靠谱客的博主 友好日记本,这篇文章主要介绍android layout_weight="0dp"原因解析,现在分享给大家,希望可以做个参考。

设置android:layout_weight="1“时,有时会发现android:layout_width="0dp",有时则发现android:layout_width="wrap_content"

其实正确的做法是android:layout_width="0dp",因为width的优先级高于weight。可参看如下链接文章

http://blog.csdn.net/u010552788/article/details/24736405


另外一盘文章:

http://blog.csdn.net/xiechengfa/article/details/38334327


 <?xml version="1.0" encoding="UTF-8"?>   
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   
    android:layout_width="fill_parent"   
    android:layout_height="match_parent"   
    android:orientation="horizontal" >   
    <TextView   
        android:background="#ff0000"   
        android:layout_width="wrap_content"   
        android:layout_height="match_parent"   
        android:text="1"   
        android:textColor="@android:color/white"   
        android:layout_weight="1"/>                  #当width=wrap_content时,权值作用为1:2:3,权值小则图像窄
    <TextView   
        android:background="#cccccc"   
        android:layout_width="wrap_content"   
        android:layout_height="match_parent"   
        android:text="2"   
        android:textColor="@android:color/black"   
        android:layout_weight="2" />   
     <TextView   
        android:background="#ddaacc"   
        android:layout_width="wrap_content"   
        android:layout_height="match_parent"   
        android:text="3"   
        android:textColor="@android:color/black"   
        android:layout_weight="3" />   
</LinearLayout> 



 <?xml version="1.0" encoding="UTF-8"?>   
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   
    android:layout_width="fill_parent"   
    android:layout_height="match_parent"   
    android:orientation="horizontal" >   
    <TextView   
        android:background="#ff0000"   
        android:layout_width="match_parent"   
        android:layout_height="match_parent"   
        android:text="1"   
        android:textColor="@android:color/white"   
        android:layout_weight="1"/>   #此时权值小则比较宽
    <TextView   
        android:background="#cccccc"   
        android:layout_width="match_parent"   
        android:layout_height="match_parent"   
        android:text="2"   
        android:textColor="@android:color/black"   
        android:layout_weight="2" />   
     
</LinearLayout> 

最后

以上就是友好日记本最近收集整理的关于android layout_weight="0dp"原因解析的全部内容,更多相关android内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部