为什么会layout_width =" WRAP_CONTENT"占用屏幕的整个宽度? [英] Why would layout_width="wrap_content" take up the entire width of the screen?

查看:608
本文介绍了为什么会layout_width =" WRAP_CONTENT"占用屏幕的整个宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过这个XML:

<TableRow >
    <Button
        android:id="@+id/buttonNext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Next"
        android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>

我希望WRAP_CONTENT只有一样宽必要在按钮上显示的文字是,但按钮垄断了屏幕的整个宽度...?

I would expect "wrap_content" to only be as wide as necessary to display the text on the button, but the button monopolizes the entire width of the screen...?

推荐答案

您的问题是,在你的XML宽度规格将被忽略。从文档来的TableRow 的:

Your problem is that the width specification in your xml is ignored. From the docs for TableRow:

通过tablerow的孩子不需要指定layout_width和layout_height在XML文件中的属性。的TableRow总是强制这些值分别MATCH_PARENT和WRAP_CONTENT。

The children of a TableRow do not need to specify the layout_width and layout_height attributes in the XML file. TableRow always enforces those values to be respectively MATCH_PARENT and WRAP_CONTENT.

P.S。你有一个令人信服的理由使用绝对像素?这通常被认为是不好的做法。

P.S. Did you have a compelling reason to use absolute pixels? That's generally considered bad practice.

P.P.S。双张贴我的答案去与双张贴您的问题。 :)

P.P.S. Double-posting my answer to go with the double-posting of your question. :)

这篇关于为什么会layout_width =&QUOT; WRAP_CONTENT&QUOT;占用屏幕的整个宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆