Prateek
Prateek

Reputation: 4013

Create a paragraph using multiple textviews using xml layout

This is my layout file by which I want to create a paragraph. i.e. The next sentence should start from the point where the previous ends up. But this ain't happen and the next sentence is coming in the next line. Actually I am going by an xml approach because each sentence is associated with database and has to be selected by user , so there is no choice by doing it using \n.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <ScrollView
        android:fillViewport="true"
        android:id="@+id/q_area"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/question_text"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:padding="10dp"
                android:text="Q1 : Select the right sentence out of these ?" />

            <LinearLayout
                android:orientation="vertical"
                android:padding="10dp"
                android:layout_below="@id/question_text"
                android:layout_marginTop="25dp"
                android:id="@+id/comprehension"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/sentence1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Reading comprehension is defined as the level of understanding of a text/message." />

                <TextView
                    android:id="@+id/sentence2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="This understanding comes from the interaction between the words that are written and how they trigger knowledge outside ." />

                <TextView
                    android:id="@+id/sentence3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Proficient reading depends on the ability to recognize words quickly and effortlessly." />

                <TextView
                    android:id="@+id/sentence4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Many educators in the USA believe that students need to learn to analyze text." />

                <TextView
                    android:id="@+id/sentence5"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="But other US educators consider this reading approach to be completely backward." />
            </LinearLayout>

            <TextView
                android:id="@+id/explanation_text"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/comprehension"
                android:layout_marginTop="25dp"
                android:padding="10dp"
                android:text="Explanation: Sentence you have selected is right?" />

            <View
                android:visibility="invisible"
                android:id="@+id/user_optionset4"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/explanation_text"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="50dp"
                />
        </RelativeLayout>
    </ScrollView>

    <LinearLayout
        android:background="@android:color/black"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <Button
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="0.3"
            android:gravity="center"
            android:padding="0dp"
            android:singleLine="true"
            android:text="P"
            android:textColor="@android:color/black" />

        <Button
            android:id="@+id/Take"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1.4"
            android:gravity="center"
            android:padding="0dp"
            android:singleLine="true"
            android:text="Done"
            android:textColor="@android:color/white" />

        <Button
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="0.3"
            android:gravity="center"
            android:padding="0dp"
            android:singleLine="true"
            android:text="N"
            android:textColor="@android:color/black" />
    </LinearLayout>

</RelativeLayout>

This is the current output :

enter image description here

Expected output , the next sentence should start at the position of yellow arrows , as shown in the image :

enter image description here

Upvotes: 1

Views: 10021

Answers (5)

Prateek
Prateek

Reputation: 4013

Finally what actualy helped me was a webview that I didn't want to go for. Also I have to use a massive javascript , to get my job done as the layout was very dynamic and the content being displayed inside the webview was coming from sqlite.

Upvotes: 0

Arunkumar
Arunkumar

Reputation: 3841

You can use something like flowlayout in android. I have never got a chance to use it, but a custom implementation of the FlowLayout is present at https://github.com/ApmeM/android-flowlayout

Note: You will need to figure out exact steps and ways to use above library. maybe someone could around could help you with that

Upvotes: 0

Sushil
Sushil

Reputation: 8488

This is what I meant in my commnet above. You should create one String in strings.xml. Do proper alignmnet there using
etc. Thne use the string in your TextView:

This privacy policy sets out how xxx uses and protects any information that you give xxx when you use this App.\n\n

xxx is committed to ensuring that your privacy is protected. If we ask you to provide certain information by which you can be identified when using this App, then you can be assured that it will only be used in accordance with this privacy statement.\n\n

xxx may change this policy from time to time by updating this page. You should check this page from time to time to ensure that you are happy with any changes. This policy is effective from 1st June 2013.\n\n

What we collect\n\n

We may collect the following information:\n • Name and job title\n • Contact information including email address\n • Demographic information such as postcode, preferences and interests\n • Other information relevant to customer surveys and/or offers\n What we do with the information we gather:\n\n

We require this information to understand your needs and provide you with a better service, and in particular for the following reasons:\n • Internal record keeping.\n • We may use the information to improve our products and services.\n • We may periodically send promotional email about new products, special offers or other information which we think you may find interesting using the email address which you have provided.\n
• From time to time, we may also use your information to contact you for market research purposes. We may contact you by email, phone, fax or mail.\n • We may use the information to customize the App according to your interests.\n\n

Security\n\n

We are committed to ensuring that your information is secure. In order to prevent unauthorised access or disclosure we have put in place suitable physical, electronic and managerial procedures to safeguard and secure the information we collect online.\n\n

How we use cookies\n\n

A cookie is a small file which asks permission to be placed on your local storage. Once you agree, the file is added and the cookie helps analyse web traffic or lets you know when you visit a particular site. Cookies allow web applications to respond to you as an individual. The web application can tailor its operations to your needs, likes and dislikes by gathering and remembering information about your preferences.\n We use traffic log cookies to identify which pages are being used. This helps us analyse data about web page traffic and improve our App in order to tailor it to customer needs. We only use this information for statistical analysis purposes and then the data is removed from the system.\n Overall, cookies help us provide you with a better App, by enabling us to monitor which pages you find useful and which you do not. A cookie in no way gives us access to your computer or any information about you, other than the data you choose to share with us.\n You can choose to accept or decline cookies. Most of the browsers automatically accept cookies, but you can usually modify your browser setting to decline cookies if you prefer. This may prevent you from taking full advantage of the App.

</string>

Upvotes: 0

Juan Cort&#233;s
Juan Cort&#233;s

Reputation: 21092

Probably the easiest way of achieving this would be a webview that you attach some css to where each sentence is a link, and that link calls a Java method that will do the desired work. Then since all the links are not blocks, they will continue where the last line ended, without a line break (unless you specifically declare one).

Some information on how to achieve the calling of Java from js can be found here

Upvotes: 1

Zax
Zax

Reputation: 3010

You can use
at the end of each text. However you need to define your string/Message in string.xml under resource. Below is an example:

<string name="sample_string"><![CDATA[some test line 1 <br />some test line 2]]></string>

For further details you can refer the below link: LINK

Upvotes: 0

Related Questions