VanechikSpace
VanechikSpace

Reputation: 555

Why isn't the button stretched to edges of the screen?

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:

enter image description here

Why isn't the button stretched to edges of the screen whereas TextView is?

Upvotes: 2

Views: 69

Answers (2)

steve
steve

Reputation: 1

if you want the button stretched to the screen edge you can write

android:layout_width="match_parent"

Upvotes: 0

JAMSHAID
JAMSHAID

Reputation: 1357

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.

Button properties

For the TextView, there is no default width set.

TextView Properties

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

attributes tab

Upvotes: 2

Related Questions