Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android LinearLayout填充宽度大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想知道为什么会这样:
<LinearLayout xmlns:android="http://scheR_306_11845@as.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://scheR_306_11845@as.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中看起来更整洁,更易于维护:

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

大佬总结

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

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。