Reputation: 1055
Yesterday I started with android programming. Now I want to create a simple layout. Here is an image:
How can I give the buttons a width of 100%? When I write
android:layout_width="0dp"
will the button no longer displayed. What is my mistake?
Here is the code again.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />
</LinearLayout>
Upvotes: 1
Views: 860
Reputation: 17142
Set the button
s' layout_width
property to match_parent
:
android:layout_width="match_parent"
PS: fill_parent
& match_parent
are the same , but the fill_parent
constant is deprecated starting from API Level 8 and is now replaced by match_parent
.
(Both constants resolve to -1
eventually)
Upvotes: 4
Reputation: 35589
use match_parent
in Button
width
android:layout_width="match_parent"
Before using match_parent
, make sure parent layout must consist full width of screen, that means parent layout must have 'match_parent' for it's width
Upvotes: 2
Reputation: 13555
Just use match_parent
or fill_parent
android:layout_width="match_parent"
OR
android:layout_width="fill_parent"
Upvotes: 2