Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9260559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:55:27+00:00 2026-06-18T12:55:27+00:00

I have a situation which I am not able to fix, hopefully I will

  • 0

I have a situation which I am not able to fix, hopefully I will get some advises from you.

The situation is simple: I have a LinearLayout in which I have a TextView with multiple lines of text. The user is able to drag the TextView around until he finds a position he likes. What is really important is that the TextView can be partially out of the LinearLayout (it will appear cut).

Here are some code samples:

 <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|center_horizontal"
        android:clipChildren="false"
        android:gravity="center_horizontal|center_vertical"
        android:orientation="vertical" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textColor="@color/text_color"
            android:textSize="16sp" />
    </LinearLayout>

As you can see the LinearLayout has clipChildren = false to allow cutoff of text.
For the textview I set a touch listener

txt.setOnTouchListener(new View.OnTouchListener() {
            int initialX = 0;
            int initialY = 0;

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getActionMasked()) {
                case MotionEvent.ACTION_DOWN:
                    initialX = (int) event.getX();
                    initialY = (int) event.getY();
                    break;
                case MotionEvent.ACTION_MOVE:
                            int currentX = (int) event.getX();
                            int currentY = (int) event.getY();
                            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) txt.getLayoutParams();

                            int left = lp.leftMargin + (currentX - initialX);
                            int top = lp.topMargin + (currentY - initialY);
                            int right = lp.rightMargin - (currentX - initialX);
                            int bottom = lp.bottomMargin - (currentY - initialY);

                            lp.rightMargin = right;
                            lp.leftMargin = left;
                            lp.bottomMargin = bottom;
                            lp.topMargin = top;

                            txt.setLayoutParams(lp);
                    break;
                default:
                    break;
                }
                return true;
            }
        });

And here is my problem: As you can see I’ve set all the layout parameters (right, left, bottom, top margins). Why is that ?

1) If I use only left/top the drag is smooth enought but text get’s wrapped at the right border instead of getting cut. Probably due to right 0 margin value.

2) If I use all margins, the text gets cut as I want, but the movement is not smooth, it just jumps around for a few pixels.

How can I fix this ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:55:29+00:00Added an answer on June 18, 2026 at 12:55 pm

    Well. this is weird. By inserting the TextView inside another LinearLayout with the same size as the initial one, makes everything smooth. I have no idea why.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have just confronted this situation which i am not able to understand: In
I have a situation in which an my Android application is not able to
I have situation in which I read a record from a database. And if
I have a situation in which a managed DLL calls some unmanaged DLL. I
I have a situation where I need to retrieve data from a query which
I have a situation in which my Java project contains resources from a different
This is a somewhat simple question, but sadly I have not been able to
I have the following situation I have one swt class which displays a simple
I have a situation in which I need to convert a text data into
I have a situation in which user can single tap a control, which show

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.