Why would layout_width=“wrap_content” take up the entire width of the screen?

…衆ロ難τιáo~ 提交于 2019-12-20 06:48:18

问题


With this 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>

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...?


回答1:


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

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. Did you have a compelling reason to use absolute pixels? That's generally considered bad practice.

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




回答2:


Have you looked at this question?

Button width in Android TableLayout

The issue could be caused by using android:stretchColumns="*" in your TableLayout, but it is difficult to tell without the rest of your XML.




回答3:


Dont understand....
Cant see layout_width attribute,layout_height attribute for TableRow.no Elements can be without these attributes.



来源:https://stackoverflow.com/questions/8369254/why-would-layout-width-wrap-content-take-up-the-entire-width-of-the-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!