XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="qwerqwerqwerqweqwerqqwerqwerqwerqweqwerqwerqwerqwerqwerwerrqwerqwerqwerqwerqwerqwerqweqwerqwerqwerqwerqwerwerrqwerqwerqwerwerqwerqwerqwerwerrqwerqwerqwer"/>
<Button
android:id="@ id/true_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="qwerqwerqwerqweqwerqqwerqwerqwerqweqwerqwerqwerqwerqwerwerrqwerqwerqwerqwerqwerqwerqweqwerqwerqwerqwerqwerwerrqwerqwerqwerwerqwerqwerqwerwerrqwerqwerqwer"/>
</LinearLayout>
Output:
Why isn't the button stretched to edges of the screen whereas TextView is?
CodePudding user response:
As you can see in the properties, the default width set for the button is 320dp
, so if you don't mention any width, it will be maxed at 320dp
. If you want to increase it, you need to enter it manually.
For the TextView
, there is no default width set.
Hence, the Button has that view.
If you want to open those properties, you can get them from here:
select your widget -> Attributes Tab -> All Attributes -> maxWidth
CodePudding user response:
if you want the button stretcged to screen edge you can write
android:layout_width="match_parent"