Android LinearLayout填充宽度

Android LinearLayout填充宽度,第1张

概述我想知道为什么会这样: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:gravity="center_vertical" a 我想知道为什么会这样:
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:orIEntation="horizontal" androID:layout_wIDth="fill_parent"    androID:gravity="center_vertical"    androID:layout_height="wrap_content" androID:layout_gravity="top"    androID:background="@drawable/gradIEnt" androID:focusable="true"    androID:paddingtop="5dip" androID:paddingBottom="5dip"    androID:focusableIntouchMode="true">        <EditText androID:ID="@+ID/searchFIEld"            androID:layout_wIDth="wrap_content" androID:layout_height="fill_parent"            androID:paddingtop="2dip" androID:paddingBottom="2dip"            androID:paddingleft="10dip" androID:paddingRight="10dip"            androID:inputType="textVisiblePassword" androID:radius="5dip"            androID:layout_marginleft="10dip"            androID:background="@drawable/search_background" androID:textcolor="#000000" />        <button androID:ID="@+ID/info" androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_marginleft="10dip"            androID:background="@drawable/info_btn" /></linearLayout>

如果我将“fill_parent”设置为我的EditText的layout_wIDth,它将占用父级的整个宽度,按钮消失(我猜它隐藏在EditText下面).

任何人都可以解释一下吗?我想让button获得自己的宽度,EditText获取剩余的宽度.

解决方法 你告诉EditText到fill_parent,因此它填满了屏幕(整个宽度,没有为你的按钮留出空间).

您希望按钮包装其内容和编辑文本以填充余数,您可以使用layout_weight属性执行此 *** 作:

<?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="wrap_content" androID:layout_gravity="top" androID:gravity="center_vertical" androID:paddingtop="5dip" androID:paddingBottom="5dip" androID:orIEntation="horizontal"><EditText    androID:ID="@+ID/searchFIEld"    androID:layout_wIDth="0dip"    androID:layout_height="fill_parent"    androID:layout_weight="1"    androID:layout_marginleft="10dip"    androID:paddingtop="2dip"    androID:paddingBottom="2dip"    androID:paddingleft="10dip"    androID:paddingRight="10dip"    androID:radius="5dip"    androID:inputType="textVisiblePassword"    androID:textcolor="#000000" /><button    androID:ID="@+ID/info"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_marginleft="10dip"    androID:text="Blah" /></linearLayout>

(我把你的可绘制参考文献用于其他人的通用)

另一方面,不要让你的XML在eclipse中看起来更整洁,更易于维护:

Window > Preferences > XML > XML files > Editor

line wIDth 120

Split multiple attributes TICK

Align final bracket UNTICK

Preserve Whitespace Tags in PcdaTA UNTICK

Clear all blank lines UNTICK

Insert Whitespace before closing TICK

Click ok

然后你可以修复你的XML文件,当你打开一个XML文件CTRL A然后CTRL SHIFT F将很好地格式化它!

总结

以上是内存溢出为你收集整理的Android LinearLayout填充宽度全部内容,希望文章能够帮你解决Android LinearLayout填充宽度所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1139152.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存