tobias
tobias

Reputation: 2362

linearlayout problem

I have a weired problem with the layout of my app. I have a listview, in which I have inserted an own layout for each item. This works nice.

Here is a part of the inserted XML layout:

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
    >
        <TextView
            android:id="@+id/label"
            android:paddingTop="2px"
            android:paddingLeft="15px"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="16sp" />
        <TextView
            android:id="@+id/price"
            android:paddingTop="2px"
            android:paddingLeft="15px"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="12sp" />
        <TextView
            android:id="@+id/days"
            android:paddingTop="2px"
            android:paddingLeft="15px"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="12sp" />
        <TextView
            android:id="@+id/test"
            android:paddingTop="2px"
            android:paddingLeft="15px"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="12sp" />
        <TextView
            android:id="@+id/status"
            android:paddingTop="2px"
            android:paddingLeft="15px"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="12sp" />
    </LinearLayout>

In my activity I am doing following:

tv = (TextView) row.findViewById(R.id.price);
tv.setText(getString(R.string.wishlist_price) + ": " + "293.99€");

getString(R.string.wishlist_price) is defined in string.xml as "Price"

Now the strange thing: For the above "293.99€" the output on the phone looks like this:

Price: 293.99€

But if I change the money, for example to 22.95€, the output looks like this:

Price:
22.95€

So it does a newline after "Price:" I cant found out what is causing this.

I tried it with "2.99€", it gives the intended output:

Price: 2.99€

Does someone has an idea what is causing the newline in the example "22.95€"?

EDIT: There are two linearlayout around the one above. Perhaps they cause this strange behavior:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
>
    <LinearLayout
        android:id="@+id/product_item"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
    >

Upvotes: 0

Views: 164

Answers (2)

tobias
tobias

Reputation: 2362

I solved it:

I changed wrap_content to fill_parent:

<TextView
                android:id="@+id/price"
                android:paddingTop="2dp"
                android:paddingLeft="15dp"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textSize="12dp" />

Upvotes: 0

Austyn Mahoney
Austyn Mahoney

Reputation: 11408

This may or may not work, but using String.format(String, Object...) seems like a good fit for what you are doing.

First change your string R.string.wishlist_price to

<string name="wishlist_price">Price: %1$s</string>

and then call it using this:

tv = (TextView) row.findViewById(R.id.price);
tv.setText(String.format(getResources().getString(R.string.wishlist_price), price));

Take a look at this for more information: Using String Resources

Upvotes: 1

Related Questions