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 9160257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:41:44+00:00 2026-06-17T13:41:44+00:00

I did myself a slide animation by playing with the margin of the components.

  • 0

I did myself a slide animation by playing with the margin of the components.

Unfortunately when I “push” the right element (an edittext) out of the screen, it resizes it instead of cutting the edge part.

I can get it to behave like I want by affecting for example 1000dp to the editText, but I want this editText to fit the width of the screen, not an hardcoded width.

Start screen :

start screen

Wrong behaviour :

wrong behaviour

Good behaviour :

Good behaviour

Here is the code of the “animation” in my custom root component :

package com.example.components;

import com.example.database.NoteDataSource;
import com.example.memonotepad.R;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.LinearLayout;
import android.app.Activity;

public class SlideRightNLeft extends LinearLayout{

private LinearLayout.LayoutParams params1;

int x;

private SlideRightNLeft srnl;

private Context context_f;

private int slideDistance;


public SlideRightNLeft(Context context) {
    super(context);
}

public SlideRightNLeft(Context context, AttributeSet attrs) {
    super(context, attrs);
    context_f = context;
    srnl = this;
    slideDistance = (int) context_f.getResources().getDimension(R.dimen.slide_distance);

}

public SlideRightNLeft(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}



public void slideLogin(){


    Thread slideIt = new Thread(new Runnable() {
        @Override
        public void run() {

            x = 0;
            params1 = new LinearLayout.LayoutParams(srnl.getChildAt(0).getWidth(), srnl.getChildAt(0).getHeight());

            while(x < slideDistance) {

                try {
                    Thread.sleep(3);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                ((Activity)context_f).runOnUiThread(new Runnable(){

                    @Override
                    public void run() {

                        int diff = x - slideDistance;

                        params1.setMargins(diff, 1, 1, 1);

                        srnl.getChildAt(0).setLayoutParams(params1);

                        srnl.invalidate();

                    }
                });

                x++;

            }
        }
    });

    slideIt.start();

}




}

Activity code :

package com.example.memonotepad;

import java.util.Calendar;
import java.util.Date;

import com.example.components.SlideRightNLeft;
import com.example.database.NoteDataSource;
import com.example.adapter.NotesAdapter;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.view.Display;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

public class MemoNotepad extends Activity {

private SlideRightNLeft mainGroupComponent;
private Button slideLogin;
private Button addNote;

private NoteDataSource nds;

private Date rightNowDate;

private ListView lvNote;

private Cursor lvCursor;

private NotesAdapter na;

private EditText edt;

public static int width;

WindowManager mWinMgr;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_memo_notepad);

    mWinMgr = (WindowManager)this.getSystemService(Context.WINDOW_SERVICE);
    width = mWinMgr.getDefaultDisplay().getWidth();

    edt = (EditText) findViewById(R.id.textBook);

    edt.setWidth(width);
    edt.setMinimumWidth(width);

    mainGroupComponent = (SlideRightNLeft) findViewById(R.id.mainGroupLayout);
    nds = new NoteDataSource(this);

    lvNote = (ListView) findViewById(R.id.listNotes);

    lvCursor = nds.getAllNotes();

    na = new NotesAdapter(this, lvCursor);
    lvNote.setAdapter(na);

    slideLogin = (Button) findViewById(R.id.login_button);
    slideLogin.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mainGroupComponent.slideLogin();
        }
    });

    addNote = (Button) findViewById(R.id.new_note);
    addNote.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Calendar rightNow = Calendar.getInstance();
            rightNowDate = rightNow.getTime();  // dt is now the new date
            nds.createNote("Note", "text inside", rightNowDate);
        }
    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_memo_notepad, menu);
    return true;
}
}
  • 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-17T13:41:45+00:00Added an answer on June 17, 2026 at 1:41 pm

    I can get it to behave like I want by affecting for example 1000dp to the editText, but I want this editText to fit the width of the screen, not an hardcoded width.

    Why not get the width of device?

    mWinMgr = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
    int displayWidth = mWinMgr.getDefaultDisplay().getWidth();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just recently found myself writing this line of code, which i did not
Did anyone tried to customize the window in which the quicktime is playing video?
After experiencing it myself, I did a quick search and found that SelectionChanged will
Sorry folks but I asked a question earlier and perhaps did not explain myself
I have a sqlite database that I did not create myself but from a
Did you used Dynamic websites before? you see its a good way for making
Did some searches here & on the 'net and haven't found a good answer
Did you ever have the following situation: you need to store information, but a
Did about 30 minutes worth of searching, found lots of relevant info, but none
Did I not get enough sleep or what? This following code var frame=document.getElementById(viewer); frame.width=100;

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.