Reputation: 437
For some reason, when creating a LinearLayout
with buttons, the leftmost buttons do not have any text.
In the layout preview, it looks fine. But on the actual device, it looks like this:
Here is the layout code:
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/minusOneButton"
android:layout_gravity="center_horizontal"
tools:text="-"
android:textSize="25sp"
android:textAlignment="center"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/minus5Button"
android:layout_gravity="center_horizontal"
tools:text="-5"
android:textSize="25sp"
android:textAlignment="center"
android:layout_below="@+id/minusOneButton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:text="+"
android:id="@+id/plusOneButton"
android:layout_gravity="center_horizontal"
android:textSize="25sp"
android:textAlignment="center"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/counterText" />
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:text="+5"
android:id="@+id/plus5Button"
android:layout_gravity="center_horizontal"
android:textSize="23sp"
android:textAlignment="center"
android:layout_below="@+id/plusOneButton"
android:layout_alignLeft="@+id/plusOneButton"
android:layout_alignStart="@+id/plusOneButton" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="0"
android:id="@+id/counterText"
android:layout_gravity="center_horizontal"
android:textSize="60dp"
android:layout_marginBottom="13dp"
android:layout_alignBottom="@+id/plus5Button"
android:layout_toRightOf="@+id/minusOneButton"
android:layout_toEndOf="@+id/minusOneButton" />
Even when having only one button in this layout, it does no show the text.
Here is the class that is used to make the class usable by other layouts:
public class HigherCounter extends LinearLayout implements View.OnClickListener{
public HigherCounter(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = LayoutInflater.from(context);
inflater.inflate(R.layout.higher_counter, this);
}
Thanks!
Upvotes: 2
Views: 1220
Reputation: 2795
You are using the tools:
namespace. this only shows up in the preview tool.
Change this to android:
if it is just static text.
Upvotes: 5
Reputation: 8254
You are using tools:text
in your first 2 buttons, and that attribute is used only to renderer the preview screen.
Replace them by android:text
and they will appear at runtime.
Upvotes: 6