Android 使用线性布局 maxWidth,不适用于 fill_parent

标签 android android-layout user-interface

使用fill_parent时,maxWidth无效。

<?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="vertical">
    <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical">
        <EditText android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:maxWidth="50dip"/>
    </LinearLayout>    
</LinearLayout>

最佳答案

maxWidth 属性对match_parent(或已弃用的fill_parent)的宽度没有影响,它们是互斥的。您需要使用 wrap_content

另外任何只有一个 child 的布局都可能被删除,例如,您可以将当前布局简化为:

<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:maxWidth="50dip"/>

关于Android 使用线性布局 maxWidth,不适用于 fill_parent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13325403/

相关文章:

java - Android - NullPointerException SimpleAdapter - 固定部分 ListView?

java - 使用 MSAL 的 Azure B2C - 注册页面不可见

android - 表格布局间距问题

android - 动态安卓:orientation value for LinearLayout depending on device orientation without the need for 2 identical XML layouts

java - 如何修改 JTextArea 中 Tab 键的行为?

objective-c - 调用 dismissPopoverAnimated 或在弹出窗口外单击一次时,弹出窗口不会被关闭

android - 每 N 秒更新一次 TextView?

java - OOM 异常 - 位图大小超出 VM 预算

android - 最新的 ADT 不允许输入宽度和高度值

c# - .NET (C#) : Getting child windows when you only have a process handle or PID?