问题
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