zoukankan      html  css  js  c++  java
  • layout-maxWidth属性用法

    对于maxWidth属性,相信大家都不陌生。不过,今天我遇到了一个问题,就是当我希望一个relayout的宽度有个最大值的时候,用maxWidth却没办法实现。这里总结下maxWidth 的用法

    1.直接作用在控件上(textview为例)

    代码如下

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.example.test1.MainActivity" >
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
           >
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
            
                android:text="dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"
                android:textSize="20dp" />
        </LinearLayout>
    
    </RelativeLayout>

    结果如下

    2)我们给textview加入maxwidth

            <TextView
                android:maxWidth="100dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:text="dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"
                android:textSize="20dp" />

    结果如下

    可以看到,这个属性发挥了效果,成功限制了textview的最大宽度

    3)如果我们把这个属性加载到它的父容器linearlayout中

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxWidth="100dp"
            android:layout_centerInParent="true" >

    结果如下

    可以看到,它是没有效果的。如果你改为

    android:layout_maxWidth 会报错

    4)现在我们尝试下一个新的属性xmlns:internal="http://schemas.android.com/apk/prv/res/android"

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="300dp"
            android:layout_centerInParent="true"
            internal:layout_maxHeight="20dp"
            internal:layout_maxWidth="100dp"
            internal:layout_minHeight="20dp" >

    结果还是没有效果。

    还是不知道到底有没有什么方法可以设置一个layout的最大宽度

  • 相关阅读:
    QQ网页强制聊天,微博一键关注
    webpack(2) 安装和使用
    webpack(1) 为什么要用构建工具
    babel来进行js转换
    less实用语法
    elasticsearch笔记(8)聚合查询
    elasticsearch笔记(7) 复合查询_boolean查询 boolsting查询 filter查询
    elasticsearch笔记(6) 删除文档delete-by-query
    elasticsearch笔记(5) java操作es的查询_04深分页scroll查询
    elasticsearch笔记(4) java操作es的查询_04----- prefix查询 fuzzy查询 wildcard查询 range查询 regexp查询
  • 原文地址:https://www.cnblogs.com/zhangshuli-1989/p/zhangshuli_maxwidth_15525142.html
Copyright © 2011-2022 走看看