3

When I type a piece of text in to a TextView, it shows it on the Emulator. When I want to leave some white space between some text, I press enter and it shows correctly in the Graphical Layout.

But whenever I start the emulator, it's all combined. On the picture below you can see that.

The left side is the Graphical layout, which is what I want. The right side is what is shown in the Emulator when I start the project.

Does anyone know how to get some white open space between text?enter image description here

This is my XML code:

<TextView
        android:id="@+id/textView1"
        android:layout_width="244dp"
        android:layout_height="270dp"
        android:layout_gravity="center"
        android:layout_weight="0.01"
        android:text="Bezoektijden    
Vrijwel iedere patiënt vindt het prettig bezoek te ontvangen. Onze ervaring is
dat een goed contact met vrienden en familie een bedrage kan leveren aan 
een spoedig herstel.

Voor de meeste afdelingen gelden de volgende bezoektijden:
van 15.15 tot 16.15 uur;
van 19.00 tot 20.00 uur.

Let op: tijdens feestdagen gelden in het RKZ andere bezoektijden dan normaal.
Bekijk de website voor bezoektijden tijdens de feestdagen.
"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="244dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.28"
        android:layout_gravity="center"
        android:text="Klik hier om de uitgebreide bezoektijden te bekijken."
        android:textAppearance="?android:attr/textAppearanceSmall" />

This is my Main activity code:

package com.example.rodekruis;

import android.os.Bundle;
importdroid.app.Activity;
import android.text.Html;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.TextView;

public class BezoekActivity extends Activity {


     TextView HyperLink;
     Spanned Text;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bezoek);

        HyperLink = (TextView)findViewById(R.id.textView2);

        Text = Html.fromHtml(" <br />" +
        "<a href='https://www.rkz.nl/bezoektijden'>Klik hier om de uitgebreide bezoektijden te bekijken.</a>");

        HyperLink.setMovementMethod(LinkMovementMethod.getInstance());
        HyperLink.setText(Text);




    }
}

Strings code:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Rodekruis</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
    <string name="title_activity_nieuws">NieuwsActivity</string>
    <string name="title_activity_afspraak">AfspraakActivity</string>
    <string name="title_activity_contact">ContactActivity</string>
    <string name="title_activity_mening">MeningActivity</string>
    <string name="title_activity_route">RouteActivity</string>
    <string name="title_activity_specialisten">SpecialistenActivity</string>
    <string name="title_activity_bwc">BWCActivity</string>
    <string name="title_activity_agenda">AgendaActivity</string>
    <string name="title_activity_info">InfoActivity</string>

</resources>

edit: enter image description here

1 Answers1

1

In your values/strings.xml add this string resource:

<string name="bezoektijden">
    Bezoektijden\n\n
    Vrijwel iedere patiënt vindt het prettig bezoek te ontvangen. Onze ervaring is
    dat een goed contact met vrienden en familie een bedrage kan leveren aan 
    een spoedig herstel.\n\n
    Voor de meeste afdelingen gelden de volgende bezoektijden:
    van 15.15 tot 16.15 uur;
    van 19.00 tot 20.00 uur.\n\n
    Let op: tijdens feestdagen gelden in het RKZ andere bezoektijden dan normaal.
    Bekijk de website voor bezoektijden tijdens de feestdagen.
</string>

The \n indicates a newline. To put an empty line between 2 lines of text, you would use two newlines, thus \n\n

In your textview refer to it:

<TextView
    android:id="@+id/textView1"
    android:layout_width="244dp"
    android:layout_height="270dp"
    android:layout_gravity="center"
    android:layout_weight="0.01"
    android:text="@string/bezoektijden"
    android:textAppearance="?android:attr/textAppearanceSmall" />
Tim
  • 41,901
  • 18
  • 127
  • 145
  • I have 9 different activitys. When i open strings.xml, i simply see all the string names from all the activity's, except for the one i'm using.(bezoektijden). That one is not in there. I'll add the strings code to the question so you can see what i mean. –  Apr 13 '16 at 10:27
  • @KoenHilarius it is not supposed to be there, that's why you have to add it. You can name the string differently if the name is already used for something else. Just copy paste it from my answer to below the `InfoActivity` line – Tim Apr 13 '16 at 10:28
  • This made the link go a bit more upwards, but there are still no white spaces in between the lines.. –  Apr 13 '16 at 10:37
  • @KoenHilarius for the textviews: get rid of the layout_weight parameters, set the height to wrap_content and width to match_parents, let me know the result – Tim Apr 13 '16 at 11:26
  • Okay the spaces are there. Only thing now, the first word of the sentence starts a bit to the right, not at the same level of the others. And the other thing, the text now is completely from the left to the right, while i wanted it centered with some space left and right. –  Apr 13 '16 at 11:53
  • I added the pic of how it looks now –  Apr 13 '16 at 11:53
  • @Koen to both textviews, add `layout_marginLeft` and `layout_marginRight` with a value of `16dp` or something to "center" the text. The first word may show different because of the `textAppearanceSmall` – Tim Apr 13 '16 at 11:58
  • Okay, so there is no fix for the first word appearing 1 cm more to the right than the others? It's really annoying –  Apr 13 '16 at 12:16
  • @KoenHilarius it probably has to do with the formatting of the string. If you would do `Bezoektijden\n\nVrijwel` instead of starting the `Vrijwel` on a separate line it will probably work as you want – Tim Apr 13 '16 at 12:22
  • Thanks, it's done. When you're here anyway, do you know how to change the color of a word? Like the "Bezoektijden" in red for example? –  Apr 13 '16 at 12:47
  • @KoenHilarius check here http://stackoverflow.com/questions/19630160/change-color-inside-strings-xml – Tim Apr 13 '16 at 12:56