Home > Back-end >  formatted html text (Spannable) dosen't fully appear inside textview and scrollview
formatted html text (Spannable) dosen't fully appear inside textview and scrollview

Time:10-04

I am trying to add privacy policy page in my app, the whole page is html content, and I used enter image description here

this priavicy policy xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
    android:padding="10dp"
    tools:context=".ui.PrivacyPolicyFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@ id/ppTV"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1.0"
             />
    </LinearLayout>

</ScrollView>

and this the fragment code

class PrivacyPolicyFragment : Fragment(), MenuProvider {

    private var _binding: FragmentPrivacyPolicyBinding? = null
    private val binding get() = _binding!!

    private val pp =
        "<h1 style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 36px; line-height: 1.1; margin: 0px 0px 18px; text-align: left;\">Privacy Policy for Dummy Blog</h1><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">At Dummy Blog, accessible from https://abtallaldigital.blogspot.com/, one of our main priorities is the privacy of our visitors. This Privacy Policy document contains types of information that is collected and recorded by Dummy Blog and how we use it.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">If you have additional questions or require more information about our Privacy Policy, do not hesitate to contact us.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">This Privacy Policy applies only to our online activities and is valid for visitors to our website with regards to the information that they shared and/or collect in Dummy Blog. This policy is not applicable to any information collected offline or via channels other than this website. Our Privacy Policy was created with the help of the&nbsp;<a href=\"https://www.termsfeed.com/privacy-policy-generator/\" style=\"background-color: transparent; box-sizing: border-box; text-decoration-line: none;\">TermsFeed Privacy Policy Generator</a>.</p><h2 style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.1; margin: 0px 0px 18px; text-align: left;\">Consent</h2><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">By using our website, you hereby consent to our Privacy Policy and agree to its terms.</p><h2 style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.1; margin: 0px 0px 18px; text-align: left;\">Information we collect</h2><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">The personal information that you are asked to provide, and the reasons why you are asked to provide it, will be made clear to you at the point we ask you to provide your personal information.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">If you contact us directly, we may receive additional information about you such as your name, email address, phone number, the contents of the message and/or attachments you may send us, and any other information you may choose to provide.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">When you register for an Account, we may ask for your contact information, including items such as name, company name, address, email address, and telephone number.</p><h2 style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.1; margin: 0px 0px 18px; text-align: left;\">How we use your information</h2><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">We use the information we collect in various ways, including to:</p><ul style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin-bottom: 10px; margin-top: 0px;\"><li style=\"box-sizing: border-box; text-align: left;\">Provide, operate, and maintain our website</li><li style=\"box-sizing: border-box; text-align: left;\">Improve, personalize, and expand our website</li><li style=\"box-sizing: border-box; text-align: left;\">Understand and analyze how you use our website</li><li style=\"box-sizing: border-box; text-align: left;\">Develop new products, services, features, and functionality</li><li style=\"box-sizing: border-box; text-align: left;\">Communicate with you, either directly or through one of our partners, including for customer service, to provide you with updates and other information relating to the website, and for marketing and promotional purposes</li><li style=\"box-sizing: border-box; text-align: left;\">Send you emails</li><li style=\"box-sizing: border-box; text-align: left;\">Find and prevent fraud</li></ul><h2 style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.1; margin: 0px 0px 18px; text-align: left;\">Log Files</h2><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">Dummy Blog follows a standard procedure of using log files. These files log visitors when they visit websites. All hosting companies do this and a part of hosting services' analytics. The information collected by log files include internet protocol (IP) addresses, browser type, Internet Service Provider (ISP), date and time stamp, referring/exit pages, and possibly the number of clicks. These are not linked to any information that is personally identifiable. The purpose of the information is for analyzing trends, administering the site, tracking users' movement on the website, and gathering demographic information.</p><h2 style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.1; margin: 0px 0px 18px; text-align: left;\">Cookies and Web Beacons</h2><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">Like any other website, Dummy Blog uses 'cookies'. These cookies are used to store information including visitors' preferences, and the pages on the website that the visitor accessed or visited. The information is used to optimize the users' experience by customizing our web page content based on visitors' browser type and/or other information.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">For more general information on cookies, please read&nbsp;<a href=\"https://www.generateprivacypolicy.com/#cookies\" style=\"background-color: transparent; box-sizing: border-box; text-decoration-line: none;\">\"Cookies\" article from the Privacy Policy Generator</a>.</p><h2 style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.1; margin: 0px 0px 18px; text-align: left;\">Advertising Partners Privacy Policies</h2><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">.You may consult this list to find the Privacy Policy for each of the advertising partners of Dummy Blog</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">Third-party ad servers or ad networks uses technologies like cookies, JavaScript, or Web Beacons that are used in their respective advertisements and links that appear on Dummy Blog, which are sent directly to users' browser. They automatically receive your IP address when this occurs. These technologies are used to measure the effectiveness of their advertising campaigns and/or to personalize the advertising content that you see on websites that you visit.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">Note that Dummy Blog has no access to or control over these cookies that are used by third-party advertisers.</p><h2 style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.1; margin: 0px 0px 18px; text-align: left;\">Third Party Privacy Policies</h2><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">Dummy Blog's Privacy Policy does not apply to other advertisers or websites. Thus, we are advising you to consult the respective Privacy Policies of these third-party ad servers for more detailed information. It may include their practices and instructions about how to opt-out of certain options.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">You can choose to disable cookies through your individual browser options. To know more detailed information about cookie management with specific web browsers, it can be found at the browsers' respective websites.</p><h2 style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.1; margin: 0px 0px 18px; text-align: left;\">CCPA Privacy Rights (Do Not Sell My Personal Information)</h2><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">Under the CCPA, among other rights, California consumers have the right to:</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">Request that a business that collects a consumer's personal data disclose the categories and specific pieces of personal data that a business has collected about consumers.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">Request that a business delete any personal data about the consumer that a business has collected.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">Request that a business that sells a consumer's personal data, not sell the consumer's personal data.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">If you make a request, we have one month to respond to you. If you would like to exercise any of these rights, please contact us.</p><h2 style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.1; margin: 0px 0px 18px; text-align: left;\">GDPR Data Protection Rights</h2><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">We would like to make sure you are fully aware of all of your data protection rights. Every user is entitled to the following:</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">The right to access – You have the right to request copies of your personal data. We may charge you a small fee for this service.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">The right to rectification – You have the right to request that we correct any information you believe is inaccurate. You also have the right to request that we complete the information you believe is incomplete.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">The right to erasure – You have the right to request that we erase your personal data, under certain conditions.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">The right to restrict processing – You have the right to request that we restrict the processing of your personal data, under certain conditions.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">The right to object to processing – You have the right to object to our processing of your personal data, under certain conditions.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">The right to data portability – You have the right to request that we transfer the data that we have collected to another organization, or directly to you, under certain conditions.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">If you make a request, we have one month to respond to you. If you would like to exercise any of these rights, please contact us.</p><h2 style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.1; margin: 0px 0px 18px; text-align: left;\">Children's Information</h2><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">Another part of our priority is adding protection for children while using the internet. We encourage parents and guardians to observe, participate in, and/or monitor and guide their online activity.</p><p style=\"background-color: white; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; margin: 0px 0px 20px; text-align: left;\">Dummy Blog does not knowingly collect any Personal Identifiable Information from children under the age of 13. If you think that your child provided this kind of information on our website, we strongly encourage you to contact us immediately and we will do our best efforts to promptly remove such information from our records. </p>"


    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        // Inflate the layout for this fragment
        _binding = FragmentPrivacyPolicyBinding.inflate(inflater, container, false)

        val menuHost = requireActivity()
        menuHost.addMenuProvider(
            this,
            viewLifecycleOwner,
            androidx.lifecycle.Lifecycle.State.CREATED
        )

        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

//        binding.ppTV.movementMethod = ScrollingMovementMethod()

        val html = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            HtmlCompat.fromHtml(pp, HtmlCompat.FROM_HTML_MODE_LEGACY)
        } else {
            @Suppress("DEPRECATION")
            Html.fromHtml(pp)
        } as Spannable

        binding.ppTV.text = html


    }

    override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
    }


    override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
        if (menuItem.itemId == android.R.id.home) {
            findNavController().navigateUp()
        }
        return super.onContextItemSelected(menuItem)
    }

}

CodePudding user response:

 //Try this view make scroll view wrap_content        

 <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

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


                <TextView
                    android:id="@ id/txt"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text=""
                    android:textSize="16sp" />
            </ScrollView>


        </LinearLayout>

CodePudding user response:

I think you are trying to make textview to fill the remaining area of the screen.

So add android:fillViewport="true" attributes to your ScrollView and make TextView match_parent

<ScrollView 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"
    android:padding="10dp"
    android:fillViewport="true"
    tools:context=".ui.PrivacyPolicyFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@ id/ppTV"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
             />
    </LinearLayout>

</ScrollView>

Edit: If you don't have other layout except the one and only TextView then you don't need scrollview at all.

Below attribute of TextView will make it scrollable.

android:scrollbars = "vertical"

So your final layout should be,

<LinearLayout 
    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"
    android:orientation="vertical">

    <TextView 
        android:id="@ id/ppTV"
        android:scrollbars = "vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

CodePudding user response:

Make your text view height wrap_content it works.

CodePudding user response:

I would change the xml to something like this:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    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=".ui.PrivacyPolicyFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="top|center"
        android:padding="10dp">

        <TextView
            android:id="@ id/ppTV"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="left"/>

    </LinearLayout>

</ScrollView>

This way, if you want to wider the paddings, a user can still scroll when touching that area.

  • Related