Android get container width instead of display width

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












I want to display a text of variable length in a cardView. To make the text fit, I split the text after every 500 Chars and add the substring to another relativeLayout which is then added to a HorizontalScrollView.
But I must define a length of the relativeLayout, otherwise it is just a long one-liner in the ScrollView. Currently I do it with display.getWidth() and then shrink it to 0.8.



The code works fine like this. But
firstly this method is depreciated and secondly is it a bit static I think.
What are better solutions?



The creation of the fragment:



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
// Inflate the layout for this fragment
View layoutView = inflater.inflate(R.layout.fragment_story,
container, false);

LinearLayout storyText = layoutView.findViewById(R.id.story_text_linear_layout);


//Here I get The width of the display:
android.view.Display display = ((android.view.WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
(int)(display.getWidth()*0.8),
ViewGroup.LayoutParams.WRAP_CONTENT
);

params.setMargins(0, 0, 10, 0);


String text = story.getStory();
while(text.length()>500)

TextView t = new TextView(storyText.getContext());
t.setText(text.substring(0,500));
text =text.substring(500);

RelativeLayout rl = new RelativeLayout(storyText.getContext());
rl.setLayoutParams(params);
rl.addView(t);
storyText.addView(rl);


TextView t = new TextView(storyText.getContext());
t.setText(text);

RelativeLayout rl = new RelativeLayout(storyText.getContext());
rl.setLayoutParams(params);

rl.addView(t);
storyText.addView(rl);


TextView author = layoutView.findViewById(R.id.author_text);
author.setText(story.getAuthor());


return layoutView;



and the xml if someone needs that to have a better understanding:



<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="xyz.myrating.stories.mystories.RecyclerList.StoryFragment">

<!-- TODO: Update blank fragment layout -->


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

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:id="@+id/LinearLayout_root_storyfrag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="40dp"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:src="@drawable/spacer" />

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

<LinearLayout
android:id="@+id/story_text_linear_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="horizontal" />
</HorizontalScrollView>


<TextView
android:id="@+id/author_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Huckleberry Finn"
android:textAlignment="textEnd" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:adjustViewBounds="true"
android:src="@drawable/spacer" />

</LinearLayout>
</android.support.v7.widget.CardView>

<RatingBar
android:id="@+id/ratingBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numStars="1"
android:paddingTop="20dp"
android:rating="1" />

</LinearLayout>








share|improve this question



















  • What exactly is the outcome you're trying to achieve ? What kind of scrolling you want ? If you have a long text and fix size card layout then it would be scroll
    – Jabbar_Jigariyo
    Jun 14 at 6:48










  • I want to display a text of variable length in a cardView. Scroll: HorizontalScrollView (Nothing more, Nothing less). Have you read the question?
    – Emanuel Graf
    Jun 14 at 16:40

















up vote
2
down vote

favorite












I want to display a text of variable length in a cardView. To make the text fit, I split the text after every 500 Chars and add the substring to another relativeLayout which is then added to a HorizontalScrollView.
But I must define a length of the relativeLayout, otherwise it is just a long one-liner in the ScrollView. Currently I do it with display.getWidth() and then shrink it to 0.8.



The code works fine like this. But
firstly this method is depreciated and secondly is it a bit static I think.
What are better solutions?



The creation of the fragment:



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
// Inflate the layout for this fragment
View layoutView = inflater.inflate(R.layout.fragment_story,
container, false);

LinearLayout storyText = layoutView.findViewById(R.id.story_text_linear_layout);


//Here I get The width of the display:
android.view.Display display = ((android.view.WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
(int)(display.getWidth()*0.8),
ViewGroup.LayoutParams.WRAP_CONTENT
);

params.setMargins(0, 0, 10, 0);


String text = story.getStory();
while(text.length()>500)

TextView t = new TextView(storyText.getContext());
t.setText(text.substring(0,500));
text =text.substring(500);

RelativeLayout rl = new RelativeLayout(storyText.getContext());
rl.setLayoutParams(params);
rl.addView(t);
storyText.addView(rl);


TextView t = new TextView(storyText.getContext());
t.setText(text);

RelativeLayout rl = new RelativeLayout(storyText.getContext());
rl.setLayoutParams(params);

rl.addView(t);
storyText.addView(rl);


TextView author = layoutView.findViewById(R.id.author_text);
author.setText(story.getAuthor());


return layoutView;



and the xml if someone needs that to have a better understanding:



<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="xyz.myrating.stories.mystories.RecyclerList.StoryFragment">

<!-- TODO: Update blank fragment layout -->


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

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:id="@+id/LinearLayout_root_storyfrag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="40dp"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:src="@drawable/spacer" />

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

<LinearLayout
android:id="@+id/story_text_linear_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="horizontal" />
</HorizontalScrollView>


<TextView
android:id="@+id/author_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Huckleberry Finn"
android:textAlignment="textEnd" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:adjustViewBounds="true"
android:src="@drawable/spacer" />

</LinearLayout>
</android.support.v7.widget.CardView>

<RatingBar
android:id="@+id/ratingBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numStars="1"
android:paddingTop="20dp"
android:rating="1" />

</LinearLayout>








share|improve this question



















  • What exactly is the outcome you're trying to achieve ? What kind of scrolling you want ? If you have a long text and fix size card layout then it would be scroll
    – Jabbar_Jigariyo
    Jun 14 at 6:48










  • I want to display a text of variable length in a cardView. Scroll: HorizontalScrollView (Nothing more, Nothing less). Have you read the question?
    – Emanuel Graf
    Jun 14 at 16:40













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I want to display a text of variable length in a cardView. To make the text fit, I split the text after every 500 Chars and add the substring to another relativeLayout which is then added to a HorizontalScrollView.
But I must define a length of the relativeLayout, otherwise it is just a long one-liner in the ScrollView. Currently I do it with display.getWidth() and then shrink it to 0.8.



The code works fine like this. But
firstly this method is depreciated and secondly is it a bit static I think.
What are better solutions?



The creation of the fragment:



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
// Inflate the layout for this fragment
View layoutView = inflater.inflate(R.layout.fragment_story,
container, false);

LinearLayout storyText = layoutView.findViewById(R.id.story_text_linear_layout);


//Here I get The width of the display:
android.view.Display display = ((android.view.WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
(int)(display.getWidth()*0.8),
ViewGroup.LayoutParams.WRAP_CONTENT
);

params.setMargins(0, 0, 10, 0);


String text = story.getStory();
while(text.length()>500)

TextView t = new TextView(storyText.getContext());
t.setText(text.substring(0,500));
text =text.substring(500);

RelativeLayout rl = new RelativeLayout(storyText.getContext());
rl.setLayoutParams(params);
rl.addView(t);
storyText.addView(rl);


TextView t = new TextView(storyText.getContext());
t.setText(text);

RelativeLayout rl = new RelativeLayout(storyText.getContext());
rl.setLayoutParams(params);

rl.addView(t);
storyText.addView(rl);


TextView author = layoutView.findViewById(R.id.author_text);
author.setText(story.getAuthor());


return layoutView;



and the xml if someone needs that to have a better understanding:



<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="xyz.myrating.stories.mystories.RecyclerList.StoryFragment">

<!-- TODO: Update blank fragment layout -->


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

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:id="@+id/LinearLayout_root_storyfrag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="40dp"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:src="@drawable/spacer" />

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

<LinearLayout
android:id="@+id/story_text_linear_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="horizontal" />
</HorizontalScrollView>


<TextView
android:id="@+id/author_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Huckleberry Finn"
android:textAlignment="textEnd" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:adjustViewBounds="true"
android:src="@drawable/spacer" />

</LinearLayout>
</android.support.v7.widget.CardView>

<RatingBar
android:id="@+id/ratingBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numStars="1"
android:paddingTop="20dp"
android:rating="1" />

</LinearLayout>








share|improve this question











I want to display a text of variable length in a cardView. To make the text fit, I split the text after every 500 Chars and add the substring to another relativeLayout which is then added to a HorizontalScrollView.
But I must define a length of the relativeLayout, otherwise it is just a long one-liner in the ScrollView. Currently I do it with display.getWidth() and then shrink it to 0.8.



The code works fine like this. But
firstly this method is depreciated and secondly is it a bit static I think.
What are better solutions?



The creation of the fragment:



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
// Inflate the layout for this fragment
View layoutView = inflater.inflate(R.layout.fragment_story,
container, false);

LinearLayout storyText = layoutView.findViewById(R.id.story_text_linear_layout);


//Here I get The width of the display:
android.view.Display display = ((android.view.WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
(int)(display.getWidth()*0.8),
ViewGroup.LayoutParams.WRAP_CONTENT
);

params.setMargins(0, 0, 10, 0);


String text = story.getStory();
while(text.length()>500)

TextView t = new TextView(storyText.getContext());
t.setText(text.substring(0,500));
text =text.substring(500);

RelativeLayout rl = new RelativeLayout(storyText.getContext());
rl.setLayoutParams(params);
rl.addView(t);
storyText.addView(rl);


TextView t = new TextView(storyText.getContext());
t.setText(text);

RelativeLayout rl = new RelativeLayout(storyText.getContext());
rl.setLayoutParams(params);

rl.addView(t);
storyText.addView(rl);


TextView author = layoutView.findViewById(R.id.author_text);
author.setText(story.getAuthor());


return layoutView;



and the xml if someone needs that to have a better understanding:



<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="xyz.myrating.stories.mystories.RecyclerList.StoryFragment">

<!-- TODO: Update blank fragment layout -->


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

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:id="@+id/LinearLayout_root_storyfrag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="40dp"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:src="@drawable/spacer" />

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

<LinearLayout
android:id="@+id/story_text_linear_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="horizontal" />
</HorizontalScrollView>


<TextView
android:id="@+id/author_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Huckleberry Finn"
android:textAlignment="textEnd" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:adjustViewBounds="true"
android:src="@drawable/spacer" />

</LinearLayout>
</android.support.v7.widget.CardView>

<RatingBar
android:id="@+id/ratingBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numStars="1"
android:paddingTop="20dp"
android:rating="1" />

</LinearLayout>










share|improve this question










share|improve this question




share|improve this question









asked Apr 28 at 10:11









Emanuel Graf

1112




1112











  • What exactly is the outcome you're trying to achieve ? What kind of scrolling you want ? If you have a long text and fix size card layout then it would be scroll
    – Jabbar_Jigariyo
    Jun 14 at 6:48










  • I want to display a text of variable length in a cardView. Scroll: HorizontalScrollView (Nothing more, Nothing less). Have you read the question?
    – Emanuel Graf
    Jun 14 at 16:40

















  • What exactly is the outcome you're trying to achieve ? What kind of scrolling you want ? If you have a long text and fix size card layout then it would be scroll
    – Jabbar_Jigariyo
    Jun 14 at 6:48










  • I want to display a text of variable length in a cardView. Scroll: HorizontalScrollView (Nothing more, Nothing less). Have you read the question?
    – Emanuel Graf
    Jun 14 at 16:40
















What exactly is the outcome you're trying to achieve ? What kind of scrolling you want ? If you have a long text and fix size card layout then it would be scroll
– Jabbar_Jigariyo
Jun 14 at 6:48




What exactly is the outcome you're trying to achieve ? What kind of scrolling you want ? If you have a long text and fix size card layout then it would be scroll
– Jabbar_Jigariyo
Jun 14 at 6:48












I want to display a text of variable length in a cardView. Scroll: HorizontalScrollView (Nothing more, Nothing less). Have you read the question?
– Emanuel Graf
Jun 14 at 16:40





I want to display a text of variable length in a cardView. Scroll: HorizontalScrollView (Nothing more, Nothing less). Have you read the question?
– Emanuel Graf
Jun 14 at 16:40











1 Answer
1






active

oldest

votes

















up vote
2
down vote













Obtaining display width is wrong for this purpose because your application is not guaranteed to be ran fullscreen.



Any android.view.View has getWidth() and getHeight() methods which return the actual width and height in the container. They will return 0 until the layout process finished, so you should obtain the values after layout has been finished. This is achieved as follows



storyFrag.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener()

@Override
public void onGlobalLayout()
storyFrag.getViewTreeObserver().removeOnGlobalLayoutListener(this)
handleYourDimensions(storyFrag.getWidth())


)


However, there is something conceptually wrong with what you are trying to achieve. You should not split your text manually, instead, set the required width of your TextView so it cuts the text for you automatically.



Also, why do you need a HorizontalScrollView for your text? Do you want the actual text container to be wider than a screen and be scrollable horizontally? This seems pretty inconvenient.






share|improve this answer





















    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "196"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f193138%2fandroid-get-container-width-instead-of-display-width%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    Obtaining display width is wrong for this purpose because your application is not guaranteed to be ran fullscreen.



    Any android.view.View has getWidth() and getHeight() methods which return the actual width and height in the container. They will return 0 until the layout process finished, so you should obtain the values after layout has been finished. This is achieved as follows



    storyFrag.getViewTreeObserver().addOnGlobalLayoutListener(
    new ViewTreeObserver.OnGlobalLayoutListener()

    @Override
    public void onGlobalLayout()
    storyFrag.getViewTreeObserver().removeOnGlobalLayoutListener(this)
    handleYourDimensions(storyFrag.getWidth())


    )


    However, there is something conceptually wrong with what you are trying to achieve. You should not split your text manually, instead, set the required width of your TextView so it cuts the text for you automatically.



    Also, why do you need a HorizontalScrollView for your text? Do you want the actual text container to be wider than a screen and be scrollable horizontally? This seems pretty inconvenient.






    share|improve this answer

























      up vote
      2
      down vote













      Obtaining display width is wrong for this purpose because your application is not guaranteed to be ran fullscreen.



      Any android.view.View has getWidth() and getHeight() methods which return the actual width and height in the container. They will return 0 until the layout process finished, so you should obtain the values after layout has been finished. This is achieved as follows



      storyFrag.getViewTreeObserver().addOnGlobalLayoutListener(
      new ViewTreeObserver.OnGlobalLayoutListener()

      @Override
      public void onGlobalLayout()
      storyFrag.getViewTreeObserver().removeOnGlobalLayoutListener(this)
      handleYourDimensions(storyFrag.getWidth())


      )


      However, there is something conceptually wrong with what you are trying to achieve. You should not split your text manually, instead, set the required width of your TextView so it cuts the text for you automatically.



      Also, why do you need a HorizontalScrollView for your text? Do you want the actual text container to be wider than a screen and be scrollable horizontally? This seems pretty inconvenient.






      share|improve this answer























        up vote
        2
        down vote










        up vote
        2
        down vote









        Obtaining display width is wrong for this purpose because your application is not guaranteed to be ran fullscreen.



        Any android.view.View has getWidth() and getHeight() methods which return the actual width and height in the container. They will return 0 until the layout process finished, so you should obtain the values after layout has been finished. This is achieved as follows



        storyFrag.getViewTreeObserver().addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener()

        @Override
        public void onGlobalLayout()
        storyFrag.getViewTreeObserver().removeOnGlobalLayoutListener(this)
        handleYourDimensions(storyFrag.getWidth())


        )


        However, there is something conceptually wrong with what you are trying to achieve. You should not split your text manually, instead, set the required width of your TextView so it cuts the text for you automatically.



        Also, why do you need a HorizontalScrollView for your text? Do you want the actual text container to be wider than a screen and be scrollable horizontally? This seems pretty inconvenient.






        share|improve this answer













        Obtaining display width is wrong for this purpose because your application is not guaranteed to be ran fullscreen.



        Any android.view.View has getWidth() and getHeight() methods which return the actual width and height in the container. They will return 0 until the layout process finished, so you should obtain the values after layout has been finished. This is achieved as follows



        storyFrag.getViewTreeObserver().addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener()

        @Override
        public void onGlobalLayout()
        storyFrag.getViewTreeObserver().removeOnGlobalLayoutListener(this)
        handleYourDimensions(storyFrag.getWidth())


        )


        However, there is something conceptually wrong with what you are trying to achieve. You should not split your text manually, instead, set the required width of your TextView so it cuts the text for you automatically.



        Also, why do you need a HorizontalScrollView for your text? Do you want the actual text container to be wider than a screen and be scrollable horizontally? This seems pretty inconvenient.







        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Jun 14 at 20:14









        Yaroslav Mytkalyk

        1213




        1213






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f193138%2fandroid-get-container-width-instead-of-display-width%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Chat program with C++ and SFML

            Function to Return a JSON Like Objects Using VBA Collections and Arrays

            Will my employers contract hold up in court?